Class: Toys::PositionalArg
- Inherits:
-
Object
- Object
- Toys::PositionalArg
- Defined in:
- toys-core/lib/toys/positional_arg.rb
Overview
Defined in the toys-core gem
Representation of a formal positional argument
Instance Attribute Summary collapse
-
#acceptor ⇒ Toys::Acceptor::Base
The effective acceptor.
-
#completion ⇒ Proc, Toys::Completion::Base
readonly
The proc that determines shell completions for the value.
-
#default ⇒ Object
readonly
The default value, which may be
nil
. -
#desc ⇒ Toys::WrappableString
The short description string.
-
#display_name ⇒ String
The displayable name.
-
#key ⇒ Symbol
readonly
The key for this arg.
-
#long_desc ⇒ Array<Toys::WrappableString>
The long description strings.
-
#type ⇒ :required, ...
readonly
Type of this argument.
Class Method Summary collapse
-
.create(key, type, accept: nil, default: nil, complete: nil, desc: nil, long_desc: nil, display_name: nil) ⇒ Toys::PositionalArg
Create a PositionalArg definition.
Instance Method Summary collapse
-
#append_long_desc(long_desc) ⇒ self
Append long description strings.
Instance Attribute Details
#acceptor ⇒ Toys::Acceptor::Base
The effective acceptor.
73 74 75 |
# File 'toys-core/lib/toys/positional_arg.rb', line 73 def acceptor @acceptor end |
#completion ⇒ Proc, Toys::Completion::Base (readonly)
The proc that determines shell completions for the value.
85 86 87 |
# File 'toys-core/lib/toys/positional_arg.rb', line 85 def completion @completion end |
#default ⇒ Object (readonly)
The default value, which may be nil
.
79 80 81 |
# File 'toys-core/lib/toys/positional_arg.rb', line 79 def default @default end |
#desc ⇒ Toys::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.
102 103 104 |
# File 'toys-core/lib/toys/positional_arg.rb', line 102 def desc @desc end |
#display_name ⇒ String
The displayable name.
127 128 129 |
# File 'toys-core/lib/toys/positional_arg.rb', line 127 def display_name @display_name end |
#key ⇒ Symbol (readonly)
The key for this arg.
61 62 63 |
# File 'toys-core/lib/toys/positional_arg.rb', line 61 def key @key end |
#long_desc ⇒ Array<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.
121 122 123 |
# File 'toys-core/lib/toys/positional_arg.rb', line 121 def long_desc @long_desc end |
#type ⇒ :required, ... (readonly)
Type of this argument.
67 68 69 |
# File 'toys-core/lib/toys/positional_arg.rb', line 67 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.
51 52 53 54 55 |
# File 'toys-core/lib/toys/positional_arg.rb', line 51 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.
160 161 162 163 |
# File 'toys-core/lib/toys/positional_arg.rb', line 160 def append_long_desc(long_desc) @long_desc.concat(WrappableString.make_array(long_desc)) self end |