Class: GLI::OptionParserFactory

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(flags, switches, accepts) ⇒ OptionParserFactory

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



6
7
8
9
10
# File 'lib/gli/option_parser_factory.rb', line 6

def initialize(flags,switches,accepts)
  @flags = flags
  @switches = switches
  @accepts = accepts
end

Instance Method Details

#option_parserObject

Return an option parser to parse the given flags, switches and accepts



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

def option_parser
  options = {}
  option_parser = OptionParser.new do |opts|
    self.class.setup_accepts(opts,@accepts)
    self.class.setup_options(opts,@switches,options)
    self.class.setup_options(opts,@flags,options)
  end
  [option_parser,options]
end