allow index sub-command completion, finally
This commit is contained in:
parent
adf861e7b7
commit
62aefa0e3b
@ -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]
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user