allow index sub-command completion, finally

This commit is contained in:
Roberto Hidalgo 2023-03-16 20:51:04 -06:00
parent adf861e7b7
commit 62aefa0e3b
2 changed files with 7 additions and 0 deletions

View File

@ -95,6 +95,12 @@ func (args *Arguments) CompletionFunction(cc *cobra.Command, provided []string,
values := []string{}
directive := cobra.ShellCompDirectiveError
if cc.HasAvailableSubCommands() && len(provided) < 1 {
// if this is an "index" command and user is providing first argument
// allow completions instead of erroring by default
directive = cobra.ShellCompDirectiveDefault
}
if expectedArgLen > 0 {
argsCompleted := len(provided)
lastArg := (*args)[len(*args)-1]

View File

@ -312,6 +312,7 @@ func (vs *ValueSource) UnmarshalYAML(node *yaml.Node) error {
var customCompleters = map[string]CompletionFunc{}
// Registers a completion function for the given command.ValueType key name
func RegisterValueSource(key string, completion CompletionFunc) {
customCompleters[key] = completion
}