Class: TabTab::Definition::Flag
- Defined in:
- lib/tabtab/definitions/flag.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
Attributes inherited from Base
#contents, #definition_block, #parent
Instance Method Summary collapse
- #definition_type ⇒ Object
-
#initialize(definition, flags, description, &block) ⇒ Flag
constructor
A new instance of Flag.
-
#matches_token?(cmd_line_token) ⇒ Boolean
Determines if current token matches this command’s flags.
-
#own_completions ⇒ Object
convert flags into –flag or -f based on length of value.
-
#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, #yield_definition_block, #yield_result_block
Constructor Details
#initialize(definition, flags, description, &block) ⇒ Flag
Returns a new instance of Flag.
4 5 6 7 8 |
# File 'lib/tabtab/definitions/flag.rb', line 4 def initialize(definition, flags, description, &block) @flags = flags.map { |flag| flag.to_s } @description = description super definition, &block end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
3 4 5 |
# File 'lib/tabtab/definitions/flag.rb', line 3 def definition @definition end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/tabtab/definitions/flag.rb', line 3 def description @description end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
3 4 5 |
# File 'lib/tabtab/definitions/flag.rb', line 3 def flags @flags end |
Instance Method Details
#definition_type ⇒ Object
10 11 12 |
# File 'lib/tabtab/definitions/flag.rb', line 10 def definition_type :flag end |
#matches_token?(cmd_line_token) ⇒ Boolean
Determines if current token matches this command’s flags
32 33 34 35 |
# File 'lib/tabtab/definitions/flag.rb', line 32 def matches_token?(cmd_line_token) return false unless cmd_line_token flags.include? cmd_line_token.gsub(/^-*/,'') end |
#own_completions ⇒ Object
convert flags into –flag or -f based on length of value
25 26 27 28 29 |
# File 'lib/tabtab/definitions/flag.rb', line 25 def own_completions flags.map do |flag| flag.size > 1 ? "--#{flag}" : "-#{flag}" end 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 |
# File 'lib/tabtab/definitions/flag.rb', line 20 def tokens_consumed definition_block.nil? ? 1 : 2 end |