Class: GLI::GLIOptionParser::NormalCommandOptionParser
- Inherits:
-
Object
- Object
- GLI::GLIOptionParser::NormalCommandOptionParser
- Defined in:
- lib/gli/gli_option_parser.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cli_options ⇒ Object
Returns the value of attribute cli_options.
Instance Method Summary collapse
- #error_handler ⇒ Object
-
#initialize(accepts) ⇒ NormalCommandOptionParser
constructor
A new instance of NormalCommandOptionParser.
- #parse!(parsing_result) ⇒ Object
Constructor Details
#initialize(accepts) ⇒ NormalCommandOptionParser
Returns a new instance of NormalCommandOptionParser.
49 50 51 |
# File 'lib/gli/gli_option_parser.rb', line 49 def initialize(accepts) @accepts = accepts end |
Instance Attribute Details
#cli_options ⇒ Object
Returns the value of attribute cli_options.
47 48 49 |
# File 'lib/gli/gli_option_parser.rb', line 47 def @cli_options end |
Instance Method Details
#error_handler ⇒ Object
53 54 55 56 57 |
# File 'lib/gli/gli_option_parser.rb', line 53 def error_handler lambda { |,extra_error_context| raise UnknownCommandArgument.new(,extra_error_context) } end |
#parse!(parsing_result) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gli/gli_option_parser.rb', line 59 def parse!(parsing_result) = {} command = parsing_result.command arguments = nil loop do option_parser_factory = OptionParserFactory.for_command(command,@accepts) option_block_parser = CommandOptionBlockParser.new(option_parser_factory, self.error_handler) option_block_parser.command = command arguments = parsing_result.arguments arguments = option_block_parser.parse!(arguments) parsing_result.["commands"][command.name] = option_parser_factory..dup [command] = option_parser_factory. command_finder = CommandFinder.new(command.commands,command.get_default_command) next_command_name = arguments.shift begin command = command_finder.find_command(next_command_name) rescue AmbiguousCommand arguments.unshift(next_command_name) break rescue UnknownCommand arguments.unshift(next_command_name) # Although command finder could certainy know if it should use # the default command, it has no way to put the "unknown command" # back into the argument stack. UGH. unless command.get_default_command.nil? command = command_finder.find_command(command.get_default_command) end break end end [command] ||= {} = [command] this_command = command.parent = while this_command.kind_of?(command.class) = [this_command] || {} [GLI::Command::PARENT] = this_command = this_command.parent = end parsing_result. = parsing_result.command = command parsing_result.arguments = Array(arguments.compact) parsing_result end |