Class: TabTab::Definition::Command
- Defined in:
- lib/tabtab/definitions/command.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Base
#contents, #definition_block, #parent
Instance Method Summary collapse
-
#default(description = nil, &block) ⇒ Object
Example usage: c.default do %w[possible values following command name] end which map to example command-line expressions: myapp this_command possible myapp this_command value myapp this_command following.
- #definition_type ⇒ Object
-
#initialize(parent, name, description, &block) ⇒ Command
constructor
A new instance of Command.
-
#matches_token?(cmd_line_token) ⇒ Boolean
Determines if current token matches this command’s name.
- #own_completions ⇒ Object
-
#tokens_consumed ⇒ Object
How many tokens/parts of a command-line expression does this Flag consume For example, the following consume 1 token: –simple -s The following consumes 2 tokens: –port 1234.
Methods inherited from Base
#[], #autocompletable?, #command, #completions_of_contents, #current_token, #definition_type?, #filtered_completions, #find_active_definition_for_last_token, #flags, #yield_definition_block, #yield_result_block
Constructor Details
#initialize(parent, name, description, &block) ⇒ Command
Returns a new instance of Command.
4 5 6 7 8 |
# File 'lib/tabtab/definitions/command.rb', line 4 def initialize(parent, name, description, &block) @name = name.to_s @description = description super parent, &block end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/tabtab/definitions/command.rb', line 3 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/tabtab/definitions/command.rb', line 3 def name @name end |
Instance Method Details
#default(description = nil, &block) ⇒ Object
Example usage:
c.default do
%w[possible values following command name]
end
which map to example command-line expressions:
myapp this_command possible
myapp this_command value
myapp this_command following
37 38 39 |
# File 'lib/tabtab/definitions/command.rb', line 37 def default(description=nil, &block) contents << TabTab::Definition::Default.new(self, description, &block) end |
#definition_type ⇒ Object
10 11 12 |
# File 'lib/tabtab/definitions/command.rb', line 10 def definition_type :command end |
#matches_token?(cmd_line_token) ⇒ Boolean
Determines if current token matches this command’s name
42 43 44 |
# File 'lib/tabtab/definitions/command.rb', line 42 def matches_token?(cmd_line_token) cmd_line_token == name end |
#own_completions ⇒ Object
25 26 27 |
# File 'lib/tabtab/definitions/command.rb', line 25 def own_completions [name] end |
#tokens_consumed ⇒ Object
How many tokens/parts of a command-line expression does this Flag consume For example, the following consume 1 token:
--simple
-s
The following consumes 2 tokens:
--port 1234
20 21 22 23 |
# File 'lib/tabtab/definitions/command.rb', line 20 def tokens_consumed return 2 if definition_block 1 end |