Class: ArgParser::PositionalArgument
- Inherits:
-
ValueArgument
- Object
- Argument
- ValueArgument
- ArgParser::PositionalArgument
- Defined in:
- lib/arg-parser/argument.rb
Overview
An argument that is set by position on the command-line. PositionalArguments do not require a –key to be specified before the argument value; they are typically used when there are a small number of mandatory arguments.
Positional arguments still have a key that is used to identify the parsed argument value in the results Struct. As such, it is not an error for a positional argument to be specified with its key - its just not mandatory for the key to be provided.
Instance Attribute Summary
Attributes inherited from ValueArgument
#sensitive, #usage_value, #validation
Attributes inherited from Argument
#default, #description, #key, #on_parse, #required, #short_key, #usage_break
Instance Method Summary collapse
-
#initialize(key, desc, opts = {}) {|val, arg, hsh| ... } ⇒ PositionalArgument
constructor
Creates a new positional argument, which is an argument value that may be specified without a keyword, in which case it is matched to the available positional arguments by its position on the command-line.
-
#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 usage display.
Methods inherited from Argument
Constructor Details
#initialize(key, desc, opts = {}) {|val, arg, hsh| ... } ⇒ PositionalArgument
Creates a new positional argument, which is an argument value that may be specified without a keyword, in which case it is matched to the available positional arguments by its position on the command-line.
316 317 318 319 |
# File 'lib/arg-parser/argument.rb', line 316 def initialize(key, desc, opts = {}, &block) super @required = opts.fetch(:required, !opts.has_key?(:default)) end |
Instance Method Details
#to_s ⇒ String
Returns the word that will appear in the help display for this argument.
323 324 325 |
# File 'lib/arg-parser/argument.rb', line 323 def to_s usage_value end |
#to_use ⇒ String
Returns the string for this argument position in a command-line usage display.
329 330 331 |
# File 'lib/arg-parser/argument.rb', line 329 def to_use required? ? usage_value : "[#{usage_value}]" end |