Class: GLI::GLIOptionParser::GlobalOptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gli/gli_option_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(option_parser_factory, command_finder) ⇒ GlobalOptionParser

Returns a new instance of GlobalOptionParser.



27
28
29
30
# File 'lib/gli/gli_option_parser.rb', line 27

def initialize(option_parser_factory,command_finder)
  @option_parser_factory = option_parser_factory
  @command_finder        = command_finder
end

Instance Attribute Details

#cli_optionsObject (readonly)

Returns the value of attribute cli_options.



25
26
27
# File 'lib/gli/gli_option_parser.rb', line 25

def cli_options
  @cli_options
end

Instance Method Details

#parse!(parsing_result) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gli/gli_option_parser.rb', line 32

def parse!(parsing_result)
  parsing_result.arguments      = GLIOptionBlockParser.new(@option_parser_factory,UnknownGlobalArgument).parse!(parsing_result.arguments)
  @cli_options = { :global => @option_parser_factory.options_hash.dup, "commands" => {} }
  parsing_result.global_options = @option_parser_factory.options_hash_with_defaults_set!
  command_name = if parsing_result.global_options[:help]
                   "help"
                 else
                   parsing_result.arguments.shift
                 end
  parsing_result.command        = @command_finder.find_command(command_name)
  parsing_result
end