diff --git a/cli/command/container/completion.go b/cli/command/container/completion.go index d26401e65fb6..24c046a8292e 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 provide 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/kill.go b/cli/command/container/kill.go index 96ce22e5ae85..0095198b5aab 100644 --- a/cli/command/container/kill.go +++ b/cli/command/container/kill.go @@ -38,6 +38,9 @@ func NewKillCommand(dockerCli command.Cli) *cobra.Command { flags := cmd.Flags() flags.StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container") + + _ = cmd.RegisterFlagCompletionFunc("signal", completeSignals) + return cmd } @@ -50,7 +53,7 @@ func runKill(ctx context.Context, dockerCli command.Cli, opts *killOptions) erro if err := <-errChan; err != nil { errs = append(errs, err.Error()) } else { - fmt.Fprintln(dockerCli.Out(), name) + _, _ = fmt.Fprintln(dockerCli.Out(), name) } } if len(errs) > 0 { diff --git a/cli/command/container/restart.go b/cli/command/container/restart.go index 0ac4fa985ef7..8e7c0d4a026f 100644 --- a/cli/command/container/restart.go +++ b/cli/command/container/restart.go @@ -43,6 +43,9 @@ func NewRestartCommand(dockerCli command.Cli) *cobra.Command { flags := cmd.Flags() flags.StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container") flags.IntVarP(&opts.timeout, "time", "t", 0, "Seconds to wait before killing the container") + + _ = cmd.RegisterFlagCompletionFunc("signal", completeSignals) + 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 } diff --git a/cli/command/container/stop.go b/cli/command/container/stop.go index c221fb4448ac..c99a7c456dbc 100644 --- a/cli/command/container/stop.go +++ b/cli/command/container/stop.go @@ -43,6 +43,9 @@ func NewStopCommand(dockerCli command.Cli) *cobra.Command { flags := cmd.Flags() flags.StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container") flags.IntVarP(&opts.timeout, "time", "t", 0, "Seconds to wait before killing the container") + + _ = cmd.RegisterFlagCompletionFunc("signal", completeSignals) + return cmd }