Class: CommandKit::Arguments::Argument Private

Inherits:
ArgumentValue show all
Defined in:
lib/command_kit/arguments/argument.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a defined argument.

Instance Attribute Summary collapse

Attributes inherited from ArgumentValue

#required

Instance Method Summary collapse

Methods inherited from ArgumentValue

#optional?, #required?

Constructor Details

#initialize(name, usage: name.to_s.upcase, required: true, repeats: false, desc:) {|(value)| ... } ⇒ Argument

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the argument.

Parameters:

  • name (Symbol)

    The name of the argument.

  • usage (String, nil) (defaults to: name.to_s.upcase)

    The usage string for the argument. Defaults to the argument's name.

  • required (Boolean) (defaults to: true)

    Specifies whether the argument is required or optional.

  • repeats (Boolean) (defaults to: false)

    Specifies whether the argument can be repeated multiple times.

  • desc (String, Array<String>)

    The description for the argument.

Yields:

  • ((value))

    If a block is given, it will be used to parse the argument's value. Note: not currently used.

Yield Parameters:

  • value (Object, nil)


48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/command_kit/arguments/argument.rb', line 48

def initialize(name, usage:    name.to_s.upcase,
                     required: true,
                     repeats:  false,
                     desc:     )
  super(
    usage:    usage,
    required: required
  )

  @name    = name
  @repeats = repeats
  @desc    = desc
end

Instance Attribute Details

#descString+ (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The argument's description.

Returns:

  • (String, Array<String>)


22
23
24
# File 'lib/command_kit/arguments/argument.rb', line 22

def desc
  @desc
end

#nameSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The argument's name.

Returns:

  • (Symbol)


17
18
19
# File 'lib/command_kit/arguments/argument.rb', line 17

def name
  @name
end

Instance Method Details

#repeats?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Specifies whether the argument can be repeated repeat times.

Returns:

  • (Boolean)


67
68
69
# File 'lib/command_kit/arguments/argument.rb', line 67

def repeats?
  @repeats
end

#usageString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The usage string for the argument.

Returns:

  • (String)


76
77
78
79
80
81
# File 'lib/command_kit/arguments/argument.rb', line 76

def usage
  string = @usage
  string = "#{string} ..." if repeats?
  string = "[#{string}]" if optional?
  string
end