diff --git a/pkg/command/arguments.go b/pkg/command/arguments.go index 3facf2e..7dd8bcb 100644 --- a/pkg/command/arguments.go +++ b/pkg/command/arguments.go @@ -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] diff --git a/pkg/command/value.go b/pkg/command/value.go index 1bd0a4f..3beb57b 100644 --- a/pkg/command/value.go +++ b/pkg/command/value.go @@ -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 }