Skip to content

Commit

Permalink
Handle null completions with a default callback
Browse files Browse the repository at this point in the history
Credits to thaJeztah

Signed-off-by: Harald Albers <[email protected]>
  • Loading branch information
albers committed Nov 8, 2024
1 parent 4525fe3 commit 06260e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cli/command/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command {

addCompletions(cmd, dockerCli)

flags.VisitAll(func(flag *pflag.Flag) {
// Set a default completion function if none was set. We don't look
// up if it does already have one set, because Cobra does this for
// us, and returns an error (which we ignore for this reason).
_ = cmd.RegisterFlagCompletionFunc(flag.Name, completion.NoComplete)
})

return cmd
}

Expand Down
7 changes: 7 additions & 0 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command {
_ = cmd.RegisterFlagCompletionFunc("detach-keys", completeDetachKeys)
addCompletions(cmd, dockerCli)

flags.VisitAll(func(flag *pflag.Flag) {
// Set a default completion function if none was set. We don't look
// up if it does already have one set, because Cobra does this for
// us, and returns an error (which we ignore for this reason).
_ = cmd.RegisterFlagCompletionFunc(flag.Name, completion.NoComplete)
})

return cmd
}

Expand Down

0 comments on commit 06260e6

Please sign in to comment.