I am using Ruby's OptionParser (require 'optparse'
) processing a "verbose" option that can be either true or false. It is in the code like this:
parser.on('-v', '--[no-]verbose', 'Verbose mode') do |v|
self.verbose = v
end
I support specifying options in an environment variable (I prepend its content to ARGV), so it is possible to set verbose mode on in that environment variable, and override it on the command line with --no-verbose
. However, I cannot find a way to override it with a short option. I've tried these without success:
-v-
-v0
-v=0
I found the source code at https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb but could not figure out the answer from that.
How can I do this?
nil
) so I am not sure why you would need to override it using the short code? You could also initialize it asfalse
e.g.def initialize; self.verbose = false; end
– Nunesrexe
. The methodprepend_environment_options
that prepends toARGV
is at github.com/keithrbennett/rexe/blob/master/exe/rexe#L53-L59 at the moment, but the code may change over time; if so, search for the method name orARGV
. – Crayton