page 240, last paragraph, lines 5-7 : the short option can have a space
… … … … … … … … … … … … … … … … … … … … … There’s one slight bit of weirdness here, which is
that a required argument is separated from a long option by a space but is flush against a
short option, so -xTHING
From the doc and experimentation, the marker can be separated by a space from the short option (it MUST be separated from a long option).
parser.on('-x XXX'
… or parser.on('-xXXX'
… have the same effect.
require "optparse"
parser = OptionParser.new
parser.on('-x XXX', '--xxx', 'Required argument via short name') do |value|
puts "option -x is '-x XXX'"
end
parser.on('-zZZZ', '--zzz', 'Required argument via short name') do |value|
puts "option -z is '-zZZZ'"
end
parser.parse!
% ruby -w rubyworld/option_doc.rb --help
Usage: option_doc [options]
-x, --xxx XXX Required argument via short name
-z, --zzzZZZ Required argument via short name
% ruby -w rubyworld/option_doc.rb -x x
option -x is '-x XXX'
% ruby -w rubyworld/option_doc.rb -z x
option -z is '-zZZZ'