From 1526a99672a707727d9d903cc67c1e3b7150fda2 Mon Sep 17 00:00:00 2001 From: Gaetan de Villele Date: Wed, 15 Mar 2017 13:49:52 -0700 Subject: [PATCH] improve semantics of utility function in cli/command/service Signed-off-by: Gaetan de Villele --- cli/command/service/create.go | 2 +- cli/command/service/opts.go | 6 ++---- cli/command/service/update.go | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cli/command/service/create.go b/cli/command/service/create.go index fc1ecbd9fe..7fd0884930 100644 --- a/cli/command/service/create.go +++ b/cli/command/service/create.go @@ -29,7 +29,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { flags.StringVar(&opts.mode, flagMode, "replicated", "Service mode (replicated or global)") flags.StringVar(&opts.name, flagName, "", "Service name") - addServiceFlags(cmd, opts) + addServiceFlags(flags, opts) flags.VarP(&opts.labels, flagLabel, "l", "Service labels") flags.Var(&opts.containerLabels, flagContainerLabel, "Container labels") diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index 46fe919606..79126217a4 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -11,7 +11,7 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/opts" runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/spf13/cobra" + "github.com/spf13/pflag" ) type int64Value interface { @@ -468,9 +468,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) { // addServiceFlags adds all flags that are common to both `create` and `update`. // Any flags that are not common are added separately in the individual command -func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) { - flags := cmd.Flags() - +func addServiceFlags(flags *pflag.FlagSet, opts *serviceOptions) { flags.StringVarP(&opts.workdir, flagWorkdir, "w", "", "Working directory inside the container") flags.StringVarP(&opts.user, flagUser, "u", "", "Username or UID (format: [:])") flags.StringVar(&opts.hostname, flagHostname, "", "Container hostname") diff --git a/cli/command/service/update.go b/cli/command/service/update.go index fc6a229fa3..7c0ef2a810 100644 --- a/cli/command/service/update.go +++ b/cli/command/service/update.go @@ -43,7 +43,7 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command { flags.SetAnnotation("rollback", "version", []string{"1.25"}) flags.Bool("force", false, "Force update even if no changes require it") flags.SetAnnotation("force", "version", []string{"1.25"}) - addServiceFlags(cmd, serviceOpts) + addServiceFlags(flags, serviceOpts) flags.Var(newListOptsVar(), flagEnvRemove, "Remove an environment variable") flags.Var(newListOptsVar(), flagGroupRemove, "Remove a previously added supplementary user group from the container")