class OptionParser::Switch::RequiredArgument
‘ARG’ is an arbitrary non-blank text
’ ARG’ giving something like ‘-X<text>=ARG’ or ‘-X<text> ARG’ where
Switch arguments should be indicated by either appending ‘=ARG’ or
switches.
where ‘X’ is the common start character for a group of short multichar
These must be defined using a format like ‘-X<text>’ or ‘-X{text}’
arguments.
multi character short switches (single ‘-’ prefix) with (optional)
Customize OptionParser RequiredArgument switch class to support
def initialize(pattern = nil, conv = nil,
def initialize(pattern = nil, conv = nil, short = nil, long = nil, arg = nil, desc = ([] if short or long), block = nil, &_block) block ||= _block super(pattern, conv, short, long, arg, desc, block) if (@long.nil? || @long.empty?) && (@arg =~ /^(<.*>|[\{].*[\}])((=|\s).*)?/) @multichar_short = true @has_arg = (@arg =~ /^(<.*>|[\{].*[\}])(=|\s).*$/ ? true : false) end end
def parse(arg, argv)
def parse(arg, argv) if @multichar_short && @has_arg # unless arg included in rest of switch or next arg is not a switch unless (arg && arg =~ /.*=.*/) || (argv.first =~ /^-/) # concatenate next arg arg ||= '' arg += "=#{argv.shift}" end end self._org_parse(arg, argv) end