I am attempting to use OptionParser to read in multiple options and have them all act on a single filename. Ex: myprogram.rb -a -b file.txt
How can I make 2 options share a mandatory argument while also allowing things like -h
to run without parameters? Currently the above line just makes -a
take -b
as its parameter.
optionparser.on("-a FILENAME", "Do this") do |a|
puts a
end
optionparser.on("-b FILENAME", "Do that") do |b|
puts b
end
EDIT:
What it is doing:
myprogram.rb -a -b file.txt
=> -b
What I need it to do:
myprogram.rb -a -b file.txt
=> file.txt
=> file.txt
Note:
These commands should be able to run independently as well as concurrently similar to ls -a ..
, ls -l ..
and ls -a -l ..
However NEITHER command should work if there is no filename given. Ideally this solution should work with any n number of options.