Class: Toys::ToolDefinition::DefaultCompletion
- Inherits:
-
Completion::Base
- Object
- Completion::Base
- Toys::ToolDefinition::DefaultCompletion
- Defined in:
- lib/toys/tool_definition.rb
Overview
A Completion that implements the default algorithm for a tool.
Instance Attribute Summary collapse
-
#delegation_target ⇒ Array<String>?
readonly
Delegation target, or nil for none.
Instance Method Summary collapse
-
#call(context) ⇒ Array<Toys::Completion::Candidate>
Returns candidates for the current completion.
-
#complete_args? ⇒ true, false
Whether to complete positional args.
-
#complete_flag_values? ⇒ true, false
Whether to complete flag values.
-
#complete_flags? ⇒ true, false
Whether to complete flags.
-
#complete_subtools? ⇒ true, false
Whether to complete subtool names.
-
#include_hidden_subtools? ⇒ true, false
Whether to include hidden subtools.
-
#initialize(complete_subtools: true, include_hidden_subtools: false, complete_args: true, complete_flags: true, complete_flag_values: true, delegation_target: nil) ⇒ DefaultCompletion
constructor
Create a completion given configuration options.
Constructor Details
#initialize(complete_subtools: true, include_hidden_subtools: false, complete_args: true, complete_flags: true, complete_flag_values: true, delegation_target: nil) ⇒ DefaultCompletion
Create a completion given configuration options.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/toys/tool_definition.rb', line 42 def initialize(complete_subtools: true, include_hidden_subtools: false, complete_args: true, complete_flags: true, complete_flag_values: true, delegation_target: nil) super() @complete_subtools = complete_subtools @include_hidden_subtools = include_hidden_subtools @complete_flags = complete_flags @complete_args = complete_args @complete_flag_values = complete_flag_values @delegation_target = delegation_target end |
Instance Attribute Details
#delegation_target ⇒ Array<String>? (readonly)
Delegation target, or nil for none.
98 99 100 |
# File 'lib/toys/tool_definition.rb', line 98 def delegation_target @delegation_target end |
Instance Method Details
#call(context) ⇒ Array<Toys::Completion::Candidate>
Returns candidates for the current completion.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/toys/tool_definition.rb', line 107 def call(context) candidates = valued_flag_candidates(context) return candidates if candidates candidates = subtool_or_arg_candidates(context) candidates += plain_flag_candidates(context) candidates += flag_value_candidates(context) if delegation_target delegate_tool = context.loader.lookup_specific(delegation_target) if delegate_tool context = context.with(previous_words: delegation_target) candidates += delegate_tool.completion.call(context) end end candidates end |
#complete_args? ⇒ true, false
Whether to complete positional args
82 83 84 |
# File 'lib/toys/tool_definition.rb', line 82 def complete_args? @complete_args end |
#complete_flag_values? ⇒ true, false
Whether to complete flag values
90 91 92 |
# File 'lib/toys/tool_definition.rb', line 90 def complete_flag_values? @complete_flag_values end |
#complete_flags? ⇒ true, false
Whether to complete flags
74 75 76 |
# File 'lib/toys/tool_definition.rb', line 74 def complete_flags? @complete_flags end |
#complete_subtools? ⇒ true, false
Whether to complete subtool names
58 59 60 |
# File 'lib/toys/tool_definition.rb', line 58 def complete_subtools? @complete_subtools end |
#include_hidden_subtools? ⇒ true, false
Whether to include hidden subtools
66 67 68 |
# File 'lib/toys/tool_definition.rb', line 66 def include_hidden_subtools? @include_hidden_subtools end |