Class: Toys::ToolDefinition::DefaultCompletion
- Inherits:
-
Completion::Base
- Object
- Completion::Base
- Toys::ToolDefinition::DefaultCompletion
- Defined in:
- toys-core/lib/toys/tool_definition.rb
Overview
Defined in the toys-core gem
A Completion that implements the default algorithm for a tool.
Instance Attribute Summary collapse
-
#delegation_target ⇒ Array<String>?
Delegation target, or nil for none.
Instance Method Summary collapse
-
#call(context) ⇒ Array<Toys::Completion::Candidate>
Returns candidates for the current completion.
-
#complete_args? ⇒ Boolean
Whether to complete positional args.
-
#complete_flag_values? ⇒ Boolean
Whether to complete flag values.
-
#complete_flags? ⇒ Boolean
Whether to complete flags.
-
#complete_subtools? ⇒ Boolean
Whether to complete subtool names.
-
#include_hidden_subtools? ⇒ Boolean
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.
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 |
# File 'toys-core/lib/toys/tool_definition.rb', line 1166 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>?
Delegation target, or nil for none.
1223 1224 1225 |
# File 'toys-core/lib/toys/tool_definition.rb', line 1223 def delegation_target @delegation_target end |
Instance Method Details
#call(context) ⇒ Array<Toys::Completion::Candidate>
Returns candidates for the current completion.
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 |
# File 'toys-core/lib/toys/tool_definition.rb', line 1232 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.cli.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? ⇒ Boolean
Whether to complete positional args
1206 1207 1208 |
# File 'toys-core/lib/toys/tool_definition.rb', line 1206 def complete_args? @complete_args end |
#complete_flag_values? ⇒ Boolean
Whether to complete flag values
1214 1215 1216 |
# File 'toys-core/lib/toys/tool_definition.rb', line 1214 def complete_flag_values? @complete_flag_values end |
#complete_flags? ⇒ Boolean
Whether to complete flags
1198 1199 1200 |
# File 'toys-core/lib/toys/tool_definition.rb', line 1198 def complete_flags? @complete_flags end |
#complete_subtools? ⇒ Boolean
Whether to complete subtool names
1182 1183 1184 |
# File 'toys-core/lib/toys/tool_definition.rb', line 1182 def complete_subtools? @complete_subtools end |
#include_hidden_subtools? ⇒ Boolean
Whether to include hidden subtools
1190 1191 1192 |
# File 'toys-core/lib/toys/tool_definition.rb', line 1190 def include_hidden_subtools? @include_hidden_subtools end |