Class: Jenkins2::CommandParser
- Inherits:
-
OptionParser
- Object
- OptionParser
- Jenkins2::CommandParser
- Defined in:
- lib/jenkins2/cmdparse.rb
Instance Attribute Summary collapse
-
#command_name ⇒ Object
readonly
Returns the value of attribute command_name.
Instance Method Summary collapse
Instance Attribute Details
#command_name ⇒ Object (readonly)
Returns the value of attribute command_name.
5 6 7 |
# File 'lib/jenkins2/cmdparse.rb', line 5 def command_name @command_name end |
Instance Method Details
#command(key, desc, &block) ⇒ Object
7 8 9 10 11 |
# File 'lib/jenkins2/cmdparse.rb', line 7 def command( key, desc, &block ) sw = OptionParser::Switch::NoArgument.new( key, nil, [key], nil, nil, [desc], Proc.new{ OptionParser.new( &block ) } ), [], [key] commands[key.to_s] = sw[0] end |
#commands ⇒ Object
26 27 28 |
# File 'lib/jenkins2/cmdparse.rb', line 26 def commands @commands ||= {} end |
#parse!(argv = default_argv) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jenkins2/cmdparse.rb', line 13 def parse!( argv=default_argv ) @command_name = argv.detect{|c| commands.has_key? c } if command_name #create temporary parser with option definitions from both: globalparse and subparse OptionParser.new do |parser| parser.instance_variable_set(:@stack, commands[command_name.to_s].block.call.instance_variable_get(:@stack) + @stack) end.parse! argv else super( argv ) end end |