Class: ArgParser::ValueArgument Abstract

Inherits:
Argument
  • Object
show all
Defined in:
lib/arg-parser/argument.rb

Overview

This class is abstract.

Abstract base class of arguments that take a value (i.e. positional and keyword arguments).

Direct Known Subclasses

KeywordArgument, PositionalArgument, RestArgument

Instance Attribute Summary collapse

Attributes inherited from Argument

#default, #description, #key, #on_parse, #required, #short_key, #usage_break

Method Summary

Methods inherited from Argument

lookup, register, to_key

Instance Attribute Details

#sensitiveBoolean Also known as: sensitive?

Returns Flag indicating that the value for this argument is a sensitive value (e.g. a password) that should not be displayed.

Returns:

  • (Boolean)

    Flag indicating that the value for this argument is a sensitive value (e.g. a password) that should not be displayed.



147
148
149
# File 'lib/arg-parser/argument.rb', line 147

def sensitive
  @sensitive
end

#usage_valueString

Returns A label that will be used in the usage string printed for this ValueArgument. If not specified, defaults to the upper-case value of the argument key. For example, if the argument key is :foo_bar, the default usage value for this argument would be FOO-BAR, as in:

Usage:
  my-prog.rb FOO-BAR.

Returns:

  • (String)

    A label that will be used in the usage string printed for this ValueArgument. If not specified, defaults to the upper-case value of the argument key. For example, if the argument key is :foo_bar, the default usage value for this argument would be FOO-BAR, as in:

    Usage:
      my-prog.rb FOO-BAR
    


168
169
170
# File 'lib/arg-parser/argument.rb', line 168

def usage_value
  @usage_value
end

#validationArray, ...

Returns An optional validation that will be applied to the argument value for this argument, to determine if it is valid. The validation can take the following forms:

@param [Array] If an Array is specified, the supplied value will be
  checked to verify it is one of the allowed values specified in the
  Array.
@param [Regexp] If a Regexp object is supplied, the argument value
  will be tested against the Regexp to verify it is valid.
@param [Proc] The most flexible option; the supplied value, this
  ValueArgument sub-class object, and the parse results (thus far)
  will be passed to the Proc for validation. The Proc must return a
  non-falsey value for the argument to be accepted.

Returns:

  • (Array, Regexp, Proc)

    An optional validation that will be applied to the argument value for this argument, to determine if it is valid. The validation can take the following forms:

    @param [Array] If an Array is specified, the supplied value will be
      checked to verify it is one of the allowed values specified in the
      Array.
    @param [Regexp] If a Regexp object is supplied, the argument value
      will be tested against the Regexp to verify it is valid.
    @param [Proc] The most flexible option; the supplied value, this
      ValueArgument sub-class object, and the parse results (thus far)
      will be passed to the Proc for validation. The Proc must return a
      non-falsey value for the argument to be accepted.
    


161
162
163
# File 'lib/arg-parser/argument.rb', line 161

def validation
  @validation
end