From d7e0a665e8e5552ad6f38a4d3e421ceef0bd294e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 6 Jul 2024 01:46:47 +0200 Subject: [PATCH] cli/command/container: add completion for --stop-signal With this patch: docker run --stop-signal ABRT IOT RTMAX-4 RTMIN RTMIN+11 TSTP ALRM KILL RTMAX-5 RTMIN+1 RTMIN+12 TTIN BUS PIPE RTMAX-6 RTMIN+2 RTMIN+13 TTOU CHLD POLL RTMAX-7 RTMIN+3 RTMIN+14 URG CLD PROF RTMAX-8 RTMIN+4 RTMIN+15 USR1 CONT PWR RTMAX-9 RTMIN+5 SEGV USR2 FPE QUIT RTMAX-10 RTMIN+6 STKFLT VTALRM HUP RTMAX RTMAX-11 RTMIN+7 STOP WINCH ILL RTMAX-1 RTMAX-12 RTMIN+8 SYS XCPU INT RTMAX-2 RTMAX-13 RTMIN+9 TERM XFSZ IO RTMAX-3 RTMAX-14 RTMIN+10 TRAP Signed-off-by: Sebastiaan van Stijn --- cli/command/container/completion.go | 10 ++++++++++ cli/command/container/create.go | 1 + cli/command/container/run.go | 1 + 3 files changed, 12 insertions(+) diff --git a/cli/command/container/completion.go b/cli/command/container/completion.go index d26401e65fb6..aca893754332 100644 --- a/cli/command/container/completion.go +++ b/cli/command/container/completion.go @@ -3,6 +3,7 @@ package container import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/container" + "github.com/moby/sys/signal" "github.com/spf13/cobra" ) @@ -82,3 +83,12 @@ func completeLinuxCapabilityNames(cmd *cobra.Command, args []string, toComplete func completeRestartPolicies(cmd *cobra.Command, args []string, toComplete string) (names []string, _ cobra.ShellCompDirective) { return completion.FromList(restartPolicies...)(cmd, args, toComplete) } + +func completeSignals(cmd *cobra.Command, args []string, toComplete string) (names []string, _ cobra.ShellCompDirective) { + // TODO(thaJeztah): do we want to provude the full list here, or a subset? + signalNames := make([]string, 0, len(signal.SignalMap)) + for k := range signal.SignalMap { + signalNames = append(signalNames, k) + } + return completion.FromList(signalNames...)(cmd, args, toComplete) +} diff --git a/cli/command/container/create.go b/cli/command/container/create.go index a14520fb1a30..0e449bb68a6e 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -85,6 +85,7 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command { _ = cmd.RegisterFlagCompletionFunc("network", completion.NetworkNames(dockerCli)) _ = cmd.RegisterFlagCompletionFunc("pull", completion.FromList(PullImageAlways, PullImageMissing, PullImageNever)) _ = cmd.RegisterFlagCompletionFunc("restart", completeRestartPolicies) + _ = cmd.RegisterFlagCompletionFunc("stop-signal", completeSignals) _ = cmd.RegisterFlagCompletionFunc("volumes-from", completion.ContainerNames(dockerCli, true)) return cmd } diff --git a/cli/command/container/run.go b/cli/command/container/run.go index 046ab599ae7d..8a3f6f58d64e 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -76,6 +76,7 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command { _ = cmd.RegisterFlagCompletionFunc("network", completion.NetworkNames(dockerCli)) _ = cmd.RegisterFlagCompletionFunc("pull", completion.FromList(PullImageAlways, PullImageMissing, PullImageNever)) _ = cmd.RegisterFlagCompletionFunc("restart", completeRestartPolicies) + _ = cmd.RegisterFlagCompletionFunc("stop-signal", completeSignals) _ = cmd.RegisterFlagCompletionFunc("volumes-from", completion.ContainerNames(dockerCli, true)) return cmd }