Class: GLI::GLIOptionParser::GlobalOptionParser
- Inherits:
-
Object
- Object
- GLI::GLIOptionParser::GlobalOptionParser
- Defined in:
- lib/gli/gli_option_parser.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(option_parser_factory, command_finder, flags, options = {}) ⇒ GlobalOptionParser
constructor
A new instance of GlobalOptionParser.
- #parse!(parsing_result) ⇒ Object
Constructor Details
#initialize(option_parser_factory, command_finder, flags, options = {}) ⇒ GlobalOptionParser
Returns a new instance of GlobalOptionParser.
39 40 41 42 43 44 |
# File 'lib/gli/gli_option_parser.rb', line 39 def initialize(option_parser_factory,command_finder,flags,={}) @option_parser_factory = option_parser_factory @command_finder = command_finder @flags = flags @options = end |
Instance Method Details
#parse!(parsing_result) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gli/gli_option_parser.rb', line 46 def parse!(parsing_result) parsing_result.arguments = GLIOptionBlockParser.new(@option_parser_factory,UnknownGlobalArgument).parse!(parsing_result.arguments) parsing_result. = @option_parser_factory. command_name = if parsing_result.[:help] || parsing_result.[:version] "help" else parsing_result.arguments.shift end parsing_result.command = begin @command_finder.find_command(command_name) rescue UnknownCommand => e raise e unless @options[:command_missing_block] command = @options[:command_missing_block].call(command_name.to_sym,parsing_result.) if command unless command.is_a?(Command) raise UnknownCommand.new("Expected the `command_missing` block to return a GLI::Command object, got a #{command.class.name} instead.") end else raise e end command end unless command_name == 'help' (@flags, parsing_result.command, parsing_result.) end parsing_result end |