Class: Toys::PositionalArg

Inherits:
Object
  • Object
show all
Defined in:
lib/toys/positional_arg.rb

Overview

Representation of a formal positional argument

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#acceptorToys::Acceptor::Base

The effective acceptor.



71
72
73
# File 'lib/toys/positional_arg.rb', line 71

def acceptor
  @acceptor
end

#completionProc, Toys::Completion::Base (readonly)

The proc that determines shell completions for the value.

Returns:



83
84
85
# File 'lib/toys/positional_arg.rb', line 83

def completion
  @completion
end

#defaultObject (readonly)

The default value, which may be nil.

Returns:

  • (Object)


77
78
79
# File 'lib/toys/positional_arg.rb', line 77

def default
  @default
end

#descToys::WrappableString

The short description string.

When reading, this is always returned as a WrappableString.

When setting, the description may be provided as any of the following:

  • A WrappableString.
  • A normal String, which will be transformed into a WrappableString using spaces as word delimiters.
  • An Array of String, which will be transformed into a WrappableString where each array element represents an individual word for wrapping.


100
101
102
# File 'lib/toys/positional_arg.rb', line 100

def desc
  @desc
end

#display_nameString

The displayable name.

Returns:

  • (String)


125
126
127
# File 'lib/toys/positional_arg.rb', line 125

def display_name
  @display_name
end

#keySymbol (readonly)

The key for this arg.

Returns:

  • (Symbol)


59
60
61
# File 'lib/toys/positional_arg.rb', line 59

def key
  @key
end

#long_descArray<Toys::WrappableString>

The long description strings.

When reading, this is returned as an Array of WrappableString representing the lines in the description.

When setting, the description must be provided as an Array where each element may be any of the following:

  • A WrappableString representing one line.
  • A normal String representing a line. This will be transformed into a WrappableString using spaces as word delimiters.
  • An Array of String representing a line. This will be transformed into a WrappableString where each array element represents an individual word for wrapping.

Returns:



119
120
121
# File 'lib/toys/positional_arg.rb', line 119

def long_desc
  @long_desc
end

#type:required, ... (readonly)

Type of this argument.

Returns:

  • (:required, :optional, :remaining)


65
66
67
# File 'lib/toys/positional_arg.rb', line 65

def type
  @type
end

Class Method Details

.create(key, type, accept: nil, default: nil, complete: nil, desc: nil, long_desc: nil, display_name: nil) ⇒ Toys::PositionalArg

Create a PositionalArg definition.

Parameters:

  • key (String, Symbol)

    The key to use to retrieve the value from the execution context.

  • type (Symbol)

    The type of arg. Valid values are :required, :optional, and :remaining.

  • accept (Object) (defaults to: nil)

    An acceptor that validates and/or converts the value. See Acceptor.create for recognized formats. Optional. If not specified, defaults to Acceptor::DEFAULT.

  • complete (Object) (defaults to: nil)

    A specifier for shell tab completion. See Completion.create for recognized formats.

  • display_name (String) (defaults to: nil)

    A name to use for display (in help text and error reports). Defaults to the key in upper case.

  • desc (String, Array<String>, Toys::WrappableString) (defaults to: nil)

    Short description for the flag. See ToolDefintion#desc for a description of the allowed formats. Defaults to the empty string.

  • long_desc (Array<String,Array<String>,Toys::WrappableString>) (defaults to: nil)

    Long description for the flag. See ToolDefintion#long_desc for a description of the allowed formats. (But note that this param takes an Array of description lines, rather than a series of arguments.) Defaults to the empty array.

Returns:



49
50
51
52
53
# File 'lib/toys/positional_arg.rb', line 49

def self.create(key, type,
                accept: nil, default: nil, complete: nil, desc: nil,
                long_desc: nil, display_name: nil)
  new(key, type, accept, default, complete, desc, long_desc, display_name)
end

Instance Method Details

#append_long_desc(long_desc) ⇒ self

Append long description strings.

You must pass an array of lines in the long description. See #long_desc for details on how each line may be represented.

Parameters:

Returns:

  • (self)


158
159
160
161
# File 'lib/toys/positional_arg.rb', line 158

def append_long_desc(long_desc)
  @long_desc.concat(WrappableString.make_array(long_desc))
  self
end