Class: CLAide::Argument

Inherits:
Object
  • Object
show all
Defined in:
lib/claide/argument.rb

Overview

This class is used to represent individual arguments to present to the command help banner

Constant Summary collapse

ELLIPSIS =

The string used for ellipsis / repeatable arguments in the banner

'...'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names, required, repeatable = false) ⇒ Argument

Returns a new instance of Argument.

Examples:


# A required parameter that can be either a NAME or URL
Argument.new(%(NAME URL), true)

Parameters:

  • names (String, Array<String>)

    List of the names of each parameter alternatives. For convenience, if there is only one alternative for that parameter, we can use a String instead of a 1-item Array

  • required (Boolean)

    true if the parameter is required, false if it is optional

  • repeatable (Boolean) (defaults to: false)

    If true, the argument can appear multiple times in the command. In that case, an ellipsis will be appended after the argument in the help banner.



47
48
49
50
51
# File 'lib/claide/argument.rb', line 47

def initialize(names, required, repeatable = false)
  @names = Array(names)
  @required = required
  @repeatable = repeatable
end

Instance Attribute Details

#namesArray<String> (readonly)

Returns List of alternate names for the parameters.

Returns:

  • (Array<String>)

    List of alternate names for the parameters



14
15
16
# File 'lib/claide/argument.rb', line 14

def names
  @names
end

#repeatableBoolean Also known as: repeatable?

Returns Indicates if the argument is repeatable (= can appear multiple times in the command, which is indicated by '...' in the banner).

Returns:

  • (Boolean)

    Indicates if the argument is repeatable (= can appear multiple times in the command, which is indicated by '...' in the banner)



26
27
28
# File 'lib/claide/argument.rb', line 26

def repeatable
  @repeatable
end

#requiredBoolean Also known as: required?

Returns Indicates if the argument is required (not optional).

Returns:

  • (Boolean)

    Indicates if the argument is required (not optional)



19
20
21
# File 'lib/claide/argument.rb', line 19

def required
  @required
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true on equality.

Parameters:

  • other (Argument)

    the Argument compared against

Returns:

  • (Boolean)

    true on equality



57
58
59
60
# File 'lib/claide/argument.rb', line 57

def ==(other)
  other.is_a?(Argument) &&
    names == other.names && required == other.required
end