Class: OptionsByExample::CommandlineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/options_by_example/commandline_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(usage) ⇒ CommandlineParser

Returns a new instance of CommandlineParser.



17
18
19
20
21
22
23
# File 'lib/options_by_example/commandline_parser.rb', line 17

def initialize(usage)
  @argument_names = usage.argument_names
  @option_names = usage.option_names

  @argument_values = {}
  @option_values = {}
end

Instance Attribute Details

#argument_valuesObject (readonly)

Returns the value of attribute argument_values.



15
16
17
# File 'lib/options_by_example/commandline_parser.rb', line 15

def argument_values
  @argument_values
end

#option_valuesObject (readonly)

Returns the value of attribute option_values.



14
15
16
# File 'lib/options_by_example/commandline_parser.rb', line 14

def option_values
  @option_values
end

Instance Method Details

#parse(argv) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/options_by_example/commandline_parser.rb', line 25

def parse(argv)
  @slices = argv.slice_before(/^-/).entries
  treat_everything_after_double_dash_as_positionals

  exit_if_help_option
  unpack_combined_shorthand_options
  expand_dash_number_to_dash_n_option
  raise_if_unknown_options

  @remainder = parse_options_and_return_remainder
  coerce_num_date_time_etc

  validate_number_of_arguments
  parse_positional_arguments

  # :nocov:
  raise %{unreachable given we check number of arguments} unless @remainder.empty?
  # :nocov:
end