aris
July 24, 2012, 9:19pm
1
Hello,
I’m using optparse for a cli script. I need an argument (-s, --sort) to
accept only 3 possible options :date, :country, :ipfreq, so here is my
piece of optparse code:
[…]
options[:sort] = :yes # <— Not sure what this does, probably sets a
default value to :sort … I just grab the code sample from the link
above
opts.on(‘-s’, ‘–sort OPT’, [:date, :country, :ip], ‘Sorts by [date,
country, ip-frequency]’) do |sort|
options[:sort] = sort
end
[…]
Now I don’t understand how to use this code in my exec function:
[…]
if File.exists?($logfile)
$f2b = F2bread.new($logfile)
if options[:info]
$f2b.info
# opts.on(‘-s’, ‘–sort OPT’, [:date, :country, :ip], ‘Sorts by
[date, country, ip-frequency]’) do |sort|
elsif options[:sort]
if options[:sort] == ‘date’
$f2b.sort_by_date
elsif options[:sort] == “country” # <— something like this?
# etc…
[…]
Any sort of hints are always welcome.
Best regards,
Panagiotis A.
atma
July 24, 2012, 10:58pm
2
On Tue, Jul 24, 2012 at 9:18 PM, Panagiotis A.
[email protected] wrote:
opts.on(‘-s’, ‘–sort OPT’, [:date, :country, :ip], ‘Sorts by [date, country,
ip-frequency]’) do |sort|
options[:sort] = sort
end
[…]
# opts.on(‘-s’, ‘–sort OPT’, [:date, :country, :ip], ‘Sorts by [date,
country, ip-frequency]’) do |sort|
elsif options[:sort]
if options[:sort] == ‘date’
$f2b.sort_by_date
elsif options[:sort] == “country” # <— something like this?
# etc…
[…]
Any sort of hints are always welcome.
$ irb19 -r optparse
irb(main):001:0> OptionParser.new {|o| o.on(“-s O”, [:a, :b]){|v| p v,
v.class}}.parse %w{-s a}
:a
Symbol
=> []
Nice pun, btw.
Kind regards
robert
atma
July 25, 2012, 3:51pm
3
Am 24.07.2012 21:18, schrieb Panagiotis A.:
if options[:sort] == 'date'
$f2b.sort_by_date
elsif options[:sort] == "country" # <--- something like this?
# etc...
you are dealing with symbols, so
if options[:sort] == :date
atma
July 25, 2012, 5:38pm
4
Hello,
Thanks for the reply Robert and Stomar
On 25 Ιουλ 2012, at 16:50 , [email protected] wrote:
–
https://github.com/stomar/
Panagiotis A.