R
Ritesh Agrawal
Hi,
I am trying to use optparse to parse an argument into an array and check
for possible values. For instance consider an argument like this
--operations count, count+, count-
I want to parse above argument into @options[perations] = ["count",
"count+", "count-"]. But at the same time I have limited vocabulary for
possible operations and I want to check for that so that if some gives
any other operation argument, it throws an error message
@OPERATIONS=["count", "count+", "count-"]
@optparse = OptionParser.new do |opts|
opts.banner = "Usage: ruby #{__FILE__}
--operations=METHOD1,METHOD2,METHOD3.."
opts.on('-o OPERATIONS', '--operations a,b,c',
@OPERATIONS, Array, "Possible operations are #{@OPERATIONS.join(', ')}"
) do |hypo|
@options[perations]=[] unless @options[perations]
@options[perations] << hypo.to_s.strip.downcase()
@options[perations] = @options[perations].uniq
end
end
@optparse.parse!
I am trying to use optparse to parse an argument into an array and check
for possible values. For instance consider an argument like this
--operations count, count+, count-
I want to parse above argument into @options[perations] = ["count",
"count+", "count-"]. But at the same time I have limited vocabulary for
possible operations and I want to check for that so that if some gives
any other operation argument, it throws an error message
@OPERATIONS=["count", "count+", "count-"]
@optparse = OptionParser.new do |opts|
opts.banner = "Usage: ruby #{__FILE__}
--operations=METHOD1,METHOD2,METHOD3.."
opts.on('-o OPERATIONS', '--operations a,b,c',
@OPERATIONS, Array, "Possible operations are #{@OPERATIONS.join(', ')}"
) do |hypo|
@options[perations]=[] unless @options[perations]
@options[perations] << hypo.to_s.strip.downcase()
@options[perations] = @options[perations].uniq
end
end
@optparse.parse!