Handle null completions with a default callback

Credits to thaJeztah

Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 06260e68f3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Harald Albers 2024-10-30 20:10:37 +00:00 committed by Sebastiaan van Stijn
parent ce77f4a545
commit 955e003345
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 14 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}