From 0641b8ba9c45999c0c2b36adb877dbf66293fda9 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 17 Jun 2016 11:19:51 -0400 Subject: [PATCH] Use flag constants for swarm flag. Signed-off-by: Daniel Nephin (cherry picked from commit c08a50dbd1bac8a0bf1c9be5e617273c19a54a2e) --- api/client/swarm/init.go | 9 ++++----- api/client/swarm/join.go | 2 +- api/client/swarm/leave.go | 2 +- api/client/swarm/update.go | 35 +++++++++++++++++------------------ 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/api/client/swarm/init.go b/api/client/swarm/init.go index 531a69c451..966eca2f24 100644 --- a/api/client/swarm/init.go +++ b/api/client/swarm/init.go @@ -20,7 +20,6 @@ type initOptions struct { } func newInitCommand(dockerCli *client.DockerCli) *cobra.Command { - var flags *pflag.FlagSet opts := initOptions{ listenAddr: NewListenAddrOption(), autoAccept: NewAutoAcceptOption(), @@ -31,12 +30,12 @@ func newInitCommand(dockerCli *client.DockerCli) *cobra.Command { Short: "Initialize a Swarm", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return runInit(dockerCli, flags, opts) + return runInit(dockerCli, cmd.Flags(), opts) }, } - flags = cmd.Flags() - flags.Var(&opts.listenAddr, flagListenAddr, "Listen address") + flags := cmd.Flags() + flags.Var(&opts.listenAddr, "listen-addr", "Listen address") flags.Var(&opts.autoAccept, flagAutoAccept, "Auto acceptance policy (worker, manager, or none)") flags.StringVar(&opts.secret, flagSecret, "", "Set secret value needed to accept nodes into cluster") flags.BoolVar(&opts.forceNewCluster, "force-new-cluster", false, "Force create a new cluster from current state.") @@ -52,7 +51,7 @@ func runInit(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts initOptions ForceNewCluster: opts.forceNewCluster, } - if flags.Changed("secret") { + if flags.Changed(flagSecret) { req.Spec.AcceptancePolicy.Policies = opts.autoAccept.Policies(&opts.secret) } else { req.Spec.AcceptancePolicy.Policies = opts.autoAccept.Policies(nil) diff --git a/api/client/swarm/join.go b/api/client/swarm/join.go index e9e0f79d50..0d3cb286cb 100644 --- a/api/client/swarm/join.go +++ b/api/client/swarm/join.go @@ -36,7 +36,7 @@ func newJoinCommand(dockerCli *client.DockerCli) *cobra.Command { flags := cmd.Flags() flags.Var(&opts.listenAddr, flagListenAddr, "Listen address") flags.BoolVar(&opts.manager, "manager", false, "Try joining as a manager.") - flags.StringVar(&opts.secret, "secret", "", "Secret for node acceptance") + flags.StringVar(&opts.secret, flagSecret, "", "Secret for node acceptance") flags.StringVar(&opts.CACertHash, "ca-hash", "", "Hash of the Root Certificate Authority certificate used for trusted join") return cmd } diff --git a/api/client/swarm/leave.go b/api/client/swarm/leave.go index 50f05c7a76..9a45148c28 100644 --- a/api/client/swarm/leave.go +++ b/api/client/swarm/leave.go @@ -39,6 +39,6 @@ func runLeave(dockerCli *client.DockerCli, opts leaveOptions) error { return err } - fmt.Fprintln(dockerCli.Out(), "Node left the default swarm.") + fmt.Fprintln(dockerCli.Out(), "Node left the swarm.") return nil } diff --git a/api/client/swarm/update.go b/api/client/swarm/update.go index a77112da44..df5d1eaec7 100644 --- a/api/client/swarm/update.go +++ b/api/client/swarm/update.go @@ -23,23 +23,22 @@ type updateOptions struct { func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command { opts := updateOptions{autoAccept: NewAutoAcceptOption()} - var flags *pflag.FlagSet cmd := &cobra.Command{ Use: "update", Short: "Update the Swarm", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return runUpdate(dockerCli, flags, opts) + return runUpdate(dockerCli, cmd.Flags(), opts) }, } - flags = cmd.Flags() - flags.Var(&opts.autoAccept, "auto-accept", "Auto acceptance policy (worker, manager or none)") - flags.StringVar(&opts.secret, "secret", "", "Set secret value needed to accept nodes into cluster") - flags.Int64Var(&opts.taskHistoryLimit, "task-history-limit", 10, "Task history retention limit") - flags.DurationVar(&opts.dispatcherHeartbeat, "dispatcher-heartbeat", time.Duration(5*time.Second), "Dispatcher heartbeat period") - flags.DurationVar(&opts.nodeCertExpiry, "cert-expiry", time.Duration(90*24*time.Hour), "Validity period for node certificates") + flags := cmd.Flags() + flags.Var(&opts.autoAccept, flagAutoAccept, "Auto acceptance policy (worker, manager or none)") + flags.StringVar(&opts.secret, flagSecret, "", "Set secret value needed to accept nodes into cluster") + flags.Int64Var(&opts.taskHistoryLimit, flagTaskHistoryLimit, 10, "Task history retention limit") + flags.DurationVar(&opts.dispatcherHeartbeat, flagDispatcherHeartbeat, time.Duration(5*time.Second), "Dispatcher heartbeat period") + flags.DurationVar(&opts.nodeCertExpiry, flagCertExpiry, time.Duration(90*24*time.Hour), "Validity period for node certificates") return cmd } @@ -69,14 +68,14 @@ func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts updateOpt func mergeSwarm(swarm *swarm.Swarm, flags *pflag.FlagSet) error { spec := &swarm.Spec - if flags.Changed("auto-accept") { - value := flags.Lookup("auto-accept").Value.(*AutoAcceptOption) + if flags.Changed(flagAutoAccept) { + value := flags.Lookup(flagAutoAccept).Value.(*AutoAcceptOption) spec.AcceptancePolicy.Policies = value.Policies(nil) } var psecret *string - if flags.Changed("secret") { - secret, _ := flags.GetString("secret") + if flags.Changed(flagSecret) { + secret, _ := flags.GetString(flagSecret) psecret = &secret } @@ -84,18 +83,18 @@ func mergeSwarm(swarm *swarm.Swarm, flags *pflag.FlagSet) error { spec.AcceptancePolicy.Policies[i].Secret = psecret } - if flags.Changed("task-history-limit") { - spec.Orchestration.TaskHistoryRetentionLimit, _ = flags.GetInt64("task-history-limit") + if flags.Changed(flagTaskHistoryLimit) { + spec.Orchestration.TaskHistoryRetentionLimit, _ = flags.GetInt64(flagTaskHistoryLimit) } - if flags.Changed("dispatcher-heartbeat") { - if v, err := flags.GetDuration("dispatcher-heartbeat"); err == nil { + if flags.Changed(flagDispatcherHeartbeat) { + if v, err := flags.GetDuration(flagDispatcherHeartbeat); err == nil { spec.Dispatcher.HeartbeatPeriod = uint64(v.Nanoseconds()) } } - if flags.Changed("cert-expiry") { - if v, err := flags.GetDuration("cert-expiry"); err == nil { + if flags.Changed(flagCertExpiry) { + if v, err := flags.GetDuration(flagCertExpiry); err == nil { spec.CAConfig.NodeCertExpiry = v } }