class CLASP::OptionAlias

A class that represents the specification for a command-line option

Attributes

action[R]

(Proc) The procedure

aliases[R]

The option's aliases array

constraint[R]

The value constraint

default_value[R]

The default value of the option

extras[R]

The option's extras

help[R]

The option's help string

name[R]

The option's name string

required_message[R]

The message to be used when reporting that a required option is missing

values_range[R]

The range of values supported by the option

Public Class Methods

new(name, aliases, help, values_range, default_value, required, required_message, constraint, extras = nil, &blk) click to toggle source

Creates an OptionSpecification instance from the given name, aliases, help, values_range, and default_value

Signature

  • Parameters

    • name (String) The name, or long-form, of the option

    • aliases (Array) 0 or more strings specifying short-form or option-value aliases

    • help (String) The help string, which may be nil

    • values_range (Array) 0 or more strings specifying values supported by the option

    • default_value (String) The default value of the option, which will be used in the case where an option is specified without a value. May be nil

    • required (boolean) Whether the option is required. May be nil

    • required_message (::String) Message to be used when reporting that a required option is missing. May be nil in which case a message of the form “<option-name> not specified; use –help for usage”. If begins with the nul character (“0”), then is used in the place of the <option-name> and placed into the rest of the standard form message

    • constraint (Hash) Constraint to be applied to the parsed values of options matching this specification. NOTE: only integer constraints are supported in the current version

    • extras An application-defined additional parameter. If nil, it is assigned an empty Hash

  • Block An optional block that is called when a matching option argument is found

NOTE: Users should prefer the +CLASP::Option()+ method

# File lib/clasp/specifications.rb, line 238
def initialize(name, aliases, help, values_range, default_value, required, required_message, constraint, extras = nil, &blk)

        check_arity_(blk, 0..3, "option")

        @name                         =    name
        @aliases                      =  (aliases || []).select { |a| a and not a.empty? }
        @help                         =    help
        @values_range         =      values_range || []
        @default_value                =     default_value
        @required                     = required
        @required_message     =   nil
        @constraint                   =       constraint || {}
        @extras                               =  extras || {}
        @action                               =  blk

        rm_name                               =  nil

        if required_message

                if "\0" == required_message[0]

                        rm_name             =  required_message[1..-1]
                end
        else

                rm_name                      =  "'#{name}'"
        end

        if rm_name

                required_message     =   "#{rm_name} not specified; use --help for usage"
        end

        @required_message     =   required_message
end

Public Instance Methods

==(rhs) click to toggle source

Compares instance against another OptionSpecification or against a name (String)

# File lib/clasp/specifications.rb, line 335
def == rhs

        case rhs
        when self.class

                return self.eql? rhs
        when String

                return name == rhs
        else

                false
        end
end
required?() click to toggle source

Indicates whether the option is required

# File lib/clasp/specifications.rb, line 285
def required?; @required; end
to_s() click to toggle source

String form of the option

# File lib/clasp/specifications.rb, line 305
def to_s

        "{#{name}; aliases=#{aliases.join(', ')}; values_range=[ #{values_range.join(', ')} ]; default_value='#{default_value}'; help='#{help}'; required?=#{required?}; required_message=#{required_message}; constraint=#{constraint}; extras=#{extras}}"
end