Class: Pdfh::Services::OptParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfh/services/opt_parser.rb

Overview

Handles Argument options

Instance Method Summary collapse

Constructor Details

#initialize(argv:, console: nil) ⇒ self

Parameters:

  • argv (Array<String>)

    command line arguments (ie. ARGV)

  • console (Pdfh::Console, nil) (defaults to: nil)


12
13
14
15
16
17
18
19
# File 'lib/pdfh/services/opt_parser.rb', line 12

def initialize(argv:, console: nil)
  @argv = argv
  @console = console || Console.new(false)
  @options = {
    verbose: false,
    dry: false
  }
end

Instance Method Details

#parse_argvHash

Returns Parsed options including flags and file arguments.

Returns:

  • (Hash)

    Parsed options including flags and file arguments



22
23
24
25
26
27
28
29
30
# File 'lib/pdfh/services/opt_parser.rb', line 22

def parse_argv
  option_parser = build_option_parser
  option_parser.parse!(@argv)
  @options
rescue OptionParser::InvalidOption => e
  @console.error_print(e.message, exit_app: false)
  @console.info option_parser.help
  exit 1
end