mirror of https://github.com/docker/cli.git
cli/command/container: add completion for --restart
With this patch: docker run --restart <TAB> always no on-failure unless-stopped Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
f30158dbf8
commit
7fe7223c2c
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue