Class: OptionsByExample::CommandlineParser
- Inherits:
-
Object
- Object
- OptionsByExample::CommandlineParser
- Defined in:
- lib/options_by_example/commandline_parser.rb
Instance Attribute Summary collapse
-
#argument_values ⇒ Object
readonly
Returns the value of attribute argument_values.
-
#option_values ⇒ Object
readonly
Returns the value of attribute option_values.
Instance Method Summary collapse
-
#initialize(usage) ⇒ CommandlineParser
constructor
A new instance of CommandlineParser.
- #parse(argv) ⇒ Object
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_values ⇒ Object (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_values ⇒ Object (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 @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 |