How to use OptionParse to allow only one flag
- by dorelal
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.