diff --git a/cli/command/container/completion.go b/cli/command/container/completion.go index b65b5ffbd98d..d26401e65fb6 100644 --- a/cli/command/container/completion.go +++ b/cli/command/container/completion.go @@ -2,6 +2,7 @@ package container import ( "github.com/docker/cli/cli/command/completion" + "github.com/docker/docker/api/types/container" "github.com/spf13/cobra" ) @@ -64,6 +65,20 @@ var allLinuxCapabilities = []string{ "CAP_CHECKPOINT_RESTORE", } +// restartPolicies is a list of all valid restart-policies.. +// +// TODO(thaJeztah): add descriptions, and enable descriptions for our completion scripts (cobra.CompletionOptions.DisableDescriptions is currently set to "true") +var restartPolicies = []string{ + string(container.RestartPolicyDisabled), + string(container.RestartPolicyAlways), + string(container.RestartPolicyOnFailure), + string(container.RestartPolicyUnlessStopped), +} + func completeLinuxCapabilityNames(cmd *cobra.Command, args []string, toComplete string) (names []string, _ cobra.ShellCompDirective) { return completion.FromList(allLinuxCapabilities...)(cmd, args, toComplete) } + +func completeRestartPolicies(cmd *cobra.Command, args []string, toComplete string) (names []string, _ cobra.ShellCompDirective) { + return completion.FromList(restartPolicies...)(cmd, args, toComplete) +} diff --git a/cli/command/container/create.go b/cli/command/container/create.go index a65d91e8db56..d080ae5ea558 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -84,6 +84,7 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command { _ = cmd.RegisterFlagCompletionFunc("env-file", completion.FileNames) _ = cmd.RegisterFlagCompletionFunc("network", completion.NetworkNames(dockerCli)) _ = cmd.RegisterFlagCompletionFunc("pull", completion.FromList(PullImageAlways, PullImageMissing, PullImageNever)) + _ = cmd.RegisterFlagCompletionFunc("restart", completeRestartPolicies) return cmd } diff --git a/cli/command/container/run.go b/cli/command/container/run.go index 5f6a4fbaae72..ae36443df4ef 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -75,6 +75,7 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command { _ = cmd.RegisterFlagCompletionFunc("env-file", completion.FileNames) _ = cmd.RegisterFlagCompletionFunc("network", completion.NetworkNames(dockerCli)) _ = cmd.RegisterFlagCompletionFunc("pull", completion.FromList(PullImageAlways, PullImageMissing, PullImageNever)) + _ = cmd.RegisterFlagCompletionFunc("restart", completeRestartPolicies) return cmd } diff --git a/cli/command/container/update.go b/cli/command/container/update.go index 997d61b354d7..275ec5f64634 100644 --- a/cli/command/container/update.go +++ b/cli/command/container/update.go @@ -83,6 +83,8 @@ func NewUpdateCommand(dockerCli command.Cli) *cobra.Command { flags.Var(&options.cpus, "cpus", "Number of CPUs") flags.SetAnnotation("cpus", "version", []string{"1.29"}) + _ = cmd.RegisterFlagCompletionFunc("restart", completeRestartPolicies) + return cmd }