Class: ArgParser::RestArgument
- Inherits:
-
ValueArgument
- Object
- Argument
- ValueArgument
- ArgParser::RestArgument
- Defined in:
- lib/arg-parser/argument.rb
Overview
A command-line argument that takes 0 to N values from the command-line.
Instance Attribute Summary
Attributes inherited from ValueArgument
#sensitive, #usage_value, #validation
Attributes inherited from Argument
#default, #description, #key, #on_parse, #short_key, #usage_break
Instance Method Summary collapse
-
#initialize(key, desc, opts = {}, &block) ⇒ RestArgument
constructor
Creates a new rest argument, which is an argument that consumes all remaining positional argument values.
- #required ⇒ Object
-
#to_s ⇒ String
The word that will appear in the help display for this argument.
-
#to_use ⇒ String
The string for this argument position in a command-line.
Methods inherited from Argument
Constructor Details
#initialize(key, desc, opts = {}, &block) ⇒ RestArgument
Creates a new rest argument, which is an argument that consumes all remaining positional argument values.
472 473 474 475 476 |
# File 'lib/arg-parser/argument.rb', line 472 def initialize(key, desc, opts = {}, &block) super @min_values = opts.fetch(:min_values, opts.fetch(:required, true) ? 1 : 0) @default = [@default] if @default.is_a?(String) end |
Instance Method Details
#required ⇒ Object
478 479 480 |
# File 'lib/arg-parser/argument.rb', line 478 def required @min_values > 0 end |
#to_s ⇒ String
Returns the word that will appear in the help display for this argument.
484 485 486 |
# File 'lib/arg-parser/argument.rb', line 484 def to_s usage_value end |
#to_use ⇒ String
Returns The string for this argument position in a command-line. usage display.
490 491 492 |
# File 'lib/arg-parser/argument.rb', line 490 def to_use required? ? "#{usage_value} [...]" : "[#{usage_value} [...]]" end |