class GLI::OptionParserFactory

Factory for creating an OptionParser based on app configuration and DSL calls

Attributes

option_parser[R]
options_hash[R]

Public Instance Methods

options_hash_with_defaults_set!() click to toggle source
# File lib/gli/option_parser_factory.rb, line 31
def options_hash_with_defaults_set!
  set_defaults(@flags,@options_hash)
  set_defaults(@switches,@options_hash)
  @options_hash
end

Public Class Methods

for_command(command,accepts) click to toggle source

Create an option parser factory for a command. This has the added feature of setting up -h and –help on the command if those options aren’t otherwise configured, e.g. to allow todo add –help as an alternate to todo help add

# File lib/gli/option_parser_factory.rb, line 9
def self.for_command(command,accepts)
  self.new(command.flags,command.switches,accepts).tap { |factory|
    add_help_switches_to_command(factory.option_parser,command)
  }
end
new(flags,switches,accepts) click to toggle source

Create an OptionParserFactory for the given flags, switches, and accepts

# File lib/gli/option_parser_factory.rb, line 17
def initialize(flags,switches,accepts)
  @flags = flags
  @switches = switches
  @options_hash = {}
  @option_parser = OptionParser.new do |opts|
    self.class.setup_accepts(opts,accepts)
    self.class.setup_options(opts,@switches,@options_hash)
    self.class.setup_options(opts,@flags,@options_hash)
  end
end