How to use OptionParse to allow only one flag
Posted
by dorelal
on Stack Overflow
See other posts from Stack Overflow
or by dorelal
Published on 2010-03-31T21:57:50Z
Indexed on
2010/03/31
22:03 UTC
Read the original article
Hit count: 304
ruby
There are only three ways to invoke install.sh
./install.sh
./install.sh --force
./install.sh -f
I can write it easily. However I am trying to make use of OptionParse. This is what I have so far.
def self.parse
option = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: ./install.sh [--force]"
opts.on('-f', '--force', '') do |dir|
option[:force] = true
end
end
begin
optparse.parse!
rescue OptionParser::InvalidOption => e
puts e
end
end
How do I provide feedback to user in case user provides something other than -f or --force.
© Stack Overflow or respective owner