class OptionParser::Switch::RequiredArgument
Customize OptionParser
RequiredArgument
switch class to support multi character short switches (single ‘-’ prefix) with (optional) arguments. These must be defined using a format like ‘-X<text>’ or ‘-X{text}’ where ‘X’ is the common start character for a group of short multichar switches. Switch arguments should be indicated by either appending ‘=ARG’ or ‘ ARG’ giving something like ‘-X<text>=ARG’ or ‘-X<text> ARG’ where ‘ARG’ is an arbitrary non-blank text
Public Class Methods
new(pattern = nil, conv = nil, short = nil, long = nil, arg = nil, desc = ([] if short or long), block = nil, &_block)
click to toggle source
Calls superclass method
# File lib/ridl/optparse_ext.rb, line 24 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
Public Instance Methods
parse(arg, argv)
click to toggle source
# File lib/ridl/optparse_ext.rb, line 35 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
Also aliased as: _org_parse