Class: OptionParser::Switch::RequiredArgument
- Inherits:
-
Object
- Object
- OptionParser::Switch::RequiredArgument
- Defined in:
- lib/ridl/optparse_ext.rb
Overview
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
Instance Method Summary collapse
- #_org_parse ⇒ Object
-
#initialize(pattern = nil, conv = nil, short = nil, long = nil, arg = nil, desc = ([] if short or long), block = nil, &_block) ⇒ RequiredArgument
constructor
A new instance of RequiredArgument.
- #parse(arg, argv) ⇒ Object
Constructor Details
#initialize(pattern = nil, conv = nil, short = nil, long = nil, arg = nil, desc = ([] if short or long), block = nil, &_block) ⇒ RequiredArgument
Returns a new instance of RequiredArgument.
24 25 26 27 28 29 30 31 32 33 |
# 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 |
Instance Method Details
#_org_parse ⇒ Object
34 |
# File 'lib/ridl/optparse_ext.rb', line 34 alias :_org_parse :parse |
#parse(arg, argv) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# 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 |