Class: GLI::GLIOptionParser

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

Overview

Parses the command-line options using an actual OptionParser

Defined Under Namespace

Classes: GlobalOptionParser, LegacyCommandOptionParser, NormalCommandOptionParser

Instance Method Summary collapse

Constructor Details

#initialize(commands, flags, switches, accepts, default_command = nil, subcommand_option_handling_strategy = :legacy) ⇒ GLIOptionParser

Returns a new instance of GLIOptionParser.



4
5
6
7
8
9
# File 'lib/gli/gli_option_parser.rb', line 4

def initialize(commands,flags,switches,accepts,default_command = nil,subcommand_option_handling_strategy=:legacy)
   command_finder       = CommandFinder.new(commands,default_command || "help")
  @global_option_parser = GlobalOptionParser.new(OptionParserFactory.new(flags,switches,accepts),command_finder)
  @accepts              = accepts
  @subcommand_option_handling_strategy = subcommand_option_handling_strategy
end

Instance Method Details

#parse_options(args) ⇒ Object

Given the command-line argument array, returns an OptionParsingResult



12
13
14
15
16
17
18
19
20
# File 'lib/gli/gli_option_parser.rb', line 12

def parse_options(args) # :nodoc:
  option_parser_class = self.class.const_get("#{@subcommand_option_handling_strategy.to_s.capitalize}CommandOptionParser")
  OptionParsingResult.new.tap { |parsing_result|
    parsing_result.arguments = args
    parsing_result = @global_option_parser.parse!(parsing_result)
    parsing_result.cli_options = @global_option_parser.cli_options
    option_parser_class.new(@accepts).parse!(parsing_result)
  }
end