Class: TabTab::Definition::Command

Inherits:
Base
  • Object
show all
Defined in:
lib/tabtab/definitions/command.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#contents, #definition_block, #parent

Instance Method Summary collapse

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

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/tabtab/definitions/command.rb', line 3

def description
  @description
end

#nameObject (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_typeObject



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

Returns:

  • (Boolean)


42
43
44
# File 'lib/tabtab/definitions/command.rb', line 42

def matches_token?(cmd_line_token)
  cmd_line_token == name
end

#own_completionsObject



25
26
27
# File 'lib/tabtab/definitions/command.rb', line 25

def own_completions
  [name]
end

#tokens_consumedObject

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