[LRUG] Chat Digest, Vol 72, Issue 15
artem avetisyan
artemave at gmail.com
Sat Jan 14 15:23:00 PST 2012
I am not sure this is going to help, but:
- sinatra does not parse options since you require 'sinatra/base' not
'sinatra'
- based on
https://github.com/sinatra/sinatra/blob/ca06364/lib/sinatra/main.rb you
should 'extend Sinatra::Delegator' not include it.
Artem
2012/1/14 <chat-request at lists.lrug.org>
> Send Chat mailing list submissions to
> chat at lists.lrug.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> or, via email, send a message with subject or body 'help' to
> chat-request at lists.lrug.org
>
> You can reach the person managing the list at
> chat-owner at lists.lrug.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Chat digest..."
>
>
> Today's Topics:
>
> 1. Extending Optparse options in Sinatra? (Jared Patterson)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 14 Jan 2012 18:01:49 +0000
> From: Jared Patterson <Jared.Patterson at betfair.com>
> To: "chat at lists.lrug.org" <chat at lists.lrug.org>
> Subject: [LRUG] Extending Optparse options in Sinatra?
> Message-ID: <CB37738A.4FE91%jared.patterson at betfair.com>
> Content-Type: text/plain; charset="windows-1252"
>
> Hey Guys,
>
> sinatra: 1.3.2
>
> I seem to have got completely stuck right at the end of building a little
> app. The app tails a log file, which each line is a monitoring event, xml
> based, and after making some decisions on the alert, I store them as hash
> keys and am using Sinatra to respond to a particular route and display all
> listed alerts (hash keys) stored. The issue is that I want to be able to
> specify some of my own options, which i'm doing by using Optparse, however
> Sinatra is already using this for its own options, and i'm confused as to
> how I can extend these built in options. From posts I have read, seems I
> need to do the following:
>
> ------------------
> require 'optparse'
> require 'logger'
> require 'rubygems'
> require 'sinatra/base'
> Include Sinatra::Delegator
>
> #
> # Classes removed to keep this short
> #
>
> # Logger Defaults
> logger = Logger.new(STDOUT)
> logger.level = Logger::INFO
>
> # Optparser Options
> options = {}
>
> OptionParser.new do |opts|
> script_name = File.basename($0)
> opts.banner = "Usage: #{script_name} [options]"
>
> opts.on('-x') { set :lock, true }
> opts.on('-e env') { |opt| set :environment, opt.to_sym }
> opts.on('-s server') { |opt| set :server, opt }
> opts.on('-p port') { |opt| set :port, opt.to_i }
> opts.on('-o addr') { |opt| set :bind, opt }
>
> opts.on('-l', '--logfilepath', 'Path to EventMonitor log file') do |opt|
> options[:logfilepath] = opt
> puts opt
> end
>
> opts.on('-v', '--verbose', 'Enable verbose logging') do
> logger.level = Logger::DEBUG
> end
>
> opts.on_tail('-h', '--help', 'Show this message') do
> puts opts.help
> exit
> end
> end.parse!
>
> raise OptionParser::MissingArgument, "logfilepath option is missing?" if
> options[:logfilepath].nil?
>
> puts options[:logfilepath]
> ------------------
>
> However, running this app specifying only "-l /path/to/my/log.file", it
> seems options[:logfilepath] just gets set to "true", any ideas?
>
>
> ------------------
> iHAM10523:~ pattersonj$ ruby ~/study/ruby/scripts/sonic_webping.rb -l
> /tmp/monitor.xml
> true
> /Users/pattersonj/study/ruby/scripts/sonic_webping.rb:20:in `initialize':
> can't convert true into String (TypeError)
> from /Users/pattersonj/study/ruby/scripts/sonic_webping.rb:20:in `open'
> from /Users/pattersonj/study/ruby/scripts/sonic_webping.rb:20:in `tail'
> from /Users/pattersonj/study/ruby/scripts/sonic_webping.rb:263
> ------------------
>
>
> Cheers,
>
> Jared Patterson
> Linux Application Engineer
> Product Delivery and Support
>
> Office: +44 (0) 20 8834 6506
> Yahoo IM: patterson.jared84
>
> Betfair. The World?s Biggest Betting Community.
>
> Please consider the environment before printing this e-mail.
> Betfair Limited | Winslow Road | Hammersmith Embankment | London | W6 9HP.
> Registered in England and Wales under company number 5140986.
>
>
> ________________________________________________________________________
> In order to protect our email recipients, Betfair Group use SkyScan from
> MessageLabs to scan all Incoming and Outgoing mail for viruses.
>
> ________________________________________________________________________
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120114/53f7eb6a/attachment.htm
> >
>
> ------------------------------
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>
> End of Chat Digest, Vol 72, Issue 15
> ************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120114/cfdf3a8c/attachment.html>
More information about the Chat
mailing list