From 955e003345d978fd57ea8f9c802d56847bec9632 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Wed, 30 Oct 2024 20:10:37 +0000 Subject: [PATCH] Handle null completions with a default callback Credits to thaJeztah Signed-off-by: Harald Albers (cherry picked from commit 06260e68f3686a0368284a8ce9b910e056bb523b) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/create.go | 7 +++++++ cli/command/container/run.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 0edd165c6b..b5965b9801 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -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 } diff --git a/cli/command/container/run.go b/cli/command/container/run.go index f7f4ca0d1f..9816c78765 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -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 }