Skip to content

Commit

Permalink
Only one of ValidArgs/ValidArgsFunction at a time
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
  • Loading branch information
marckhouzam committed Apr 3, 2020
1 parent 835ea20 commit 7b6f441
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bash_completions.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ In some cases it is not possible to provide a list of possible completions in ad

#### 1. Custom completions of nouns written in Go

In a similar fashion as for static completions, you can use the `validArgsFunction` field to provide a Go function that Cobra will execute when it needs the list of completion choices for the nouns of a command. Simplified code from `helm status` looks like:
In a similar fashion as for static completions, you can use the `ValidArgsFunction` field to provide a Go function that Cobra will execute when it needs the list of completion choices for the nouns of a command. Note that either `ValidArgs` or `ValidArgsFunction` can be used for a single cobra command, but not both.
Simplified code from `helm status` looks like:

```go
cmd := &cobra.Command{
Expand Down
1 change: 1 addition & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Command struct {
ValidArgs []string
// ValidArgsFunction is an optional function that provides valid non-flag arguments for bash completion.
// It is a dynamic version of using ValidArgs.
// Only one of ValidArgs and ValidArgsFunction can be used for a command.
ValidArgsFunction func(cmd *Command, args []string, toComplete string) ([]string, BashCompDirective)

// Expected arguments
Expand Down

0 comments on commit 7b6f441

Please sign in to comment.