Method: GLI::GLIOptionBlockParser#initialize

Defined in:
lib/gli/gli_option_block_parser.rb

#initialize(option_parser_factory, exception_klass_or_block) ⇒ GLIOptionBlockParser

Create the parser using the given OptionParser instance and exception handling strategy.

option_parser_factory

An OptionParserFactory instance, configured to parse wherever you are on the command line

exception_klass_or_block

means of handling exceptions from OptionParser. One of:

an exception class

will be raised on errors with a message

lambda/block

will be called with a single argument - the error message.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gli/gli_option_block_parser.rb', line 14

def initialize(option_parser_factory,exception_klass_or_block)
  @option_parser_factory = option_parser_factory
  @extra_error_context = nil
  @exception_handler = if exception_klass_or_block.kind_of?(Class)
                         lambda { |message,extra_error_context|
                           raise exception_klass_or_block,message
                         }
                       else
                         exception_klass_or_block
                       end
end