Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -20,7 +20,6 @@ type initOptions struct {
|
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
func newInitCommand(dockerCli *client.DockerCli) *cobra.Command {
|
| 23 |
- var flags *pflag.FlagSet |
|
| 24 | 23 |
opts := initOptions{
|
| 25 | 24 |
listenAddr: NewListenAddrOption(), |
| 26 | 25 |
autoAccept: NewAutoAcceptOption(), |
| ... | ... |
@@ -31,12 +30,12 @@ func newInitCommand(dockerCli *client.DockerCli) *cobra.Command {
|
| 31 | 31 |
Short: "Initialize a Swarm", |
| 32 | 32 |
Args: cli.NoArgs, |
| 33 | 33 |
RunE: func(cmd *cobra.Command, args []string) error {
|
| 34 |
- return runInit(dockerCli, flags, opts) |
|
| 34 |
+ return runInit(dockerCli, cmd.Flags(), opts) |
|
| 35 | 35 |
}, |
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 |
- flags = cmd.Flags() |
|
| 39 |
- flags.Var(&opts.listenAddr, flagListenAddr, "Listen address") |
|
| 38 |
+ flags := cmd.Flags() |
|
| 39 |
+ flags.Var(&opts.listenAddr, "listen-addr", "Listen address") |
|
| 40 | 40 |
flags.Var(&opts.autoAccept, flagAutoAccept, "Auto acceptance policy (worker, manager, or none)") |
| 41 | 41 |
flags.StringVar(&opts.secret, flagSecret, "", "Set secret value needed to accept nodes into cluster") |
| 42 | 42 |
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 |
| 52 | 52 |
ForceNewCluster: opts.forceNewCluster, |
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 |
- if flags.Changed("secret") {
|
|
| 55 |
+ if flags.Changed(flagSecret) {
|
|
| 56 | 56 |
req.Spec.AcceptancePolicy.Policies = opts.autoAccept.Policies(&opts.secret) |
| 57 | 57 |
} else {
|
| 58 | 58 |
req.Spec.AcceptancePolicy.Policies = opts.autoAccept.Policies(nil) |
| ... | ... |
@@ -36,7 +36,7 @@ func newJoinCommand(dockerCli *client.DockerCli) *cobra.Command {
|
| 36 | 36 |
flags := cmd.Flags() |
| 37 | 37 |
flags.Var(&opts.listenAddr, flagListenAddr, "Listen address") |
| 38 | 38 |
flags.BoolVar(&opts.manager, "manager", false, "Try joining as a manager.") |
| 39 |
- flags.StringVar(&opts.secret, "secret", "", "Secret for node acceptance") |
|
| 39 |
+ flags.StringVar(&opts.secret, flagSecret, "", "Secret for node acceptance") |
|
| 40 | 40 |
flags.StringVar(&opts.CACertHash, "ca-hash", "", "Hash of the Root Certificate Authority certificate used for trusted join") |
| 41 | 41 |
return cmd |
| 42 | 42 |
} |
| ... | ... |
@@ -23,23 +23,22 @@ type updateOptions struct {
|
| 23 | 23 |
|
| 24 | 24 |
func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
|
| 25 | 25 |
opts := updateOptions{autoAccept: NewAutoAcceptOption()}
|
| 26 |
- var flags *pflag.FlagSet |
|
| 27 | 26 |
|
| 28 | 27 |
cmd := &cobra.Command{
|
| 29 | 28 |
Use: "update", |
| 30 | 29 |
Short: "Update the Swarm", |
| 31 | 30 |
Args: cli.NoArgs, |
| 32 | 31 |
RunE: func(cmd *cobra.Command, args []string) error {
|
| 33 |
- return runUpdate(dockerCli, flags, opts) |
|
| 32 |
+ return runUpdate(dockerCli, cmd.Flags(), opts) |
|
| 34 | 33 |
}, |
| 35 | 34 |
} |
| 36 | 35 |
|
| 37 |
- flags = cmd.Flags() |
|
| 38 |
- flags.Var(&opts.autoAccept, "auto-accept", "Auto acceptance policy (worker, manager or none)") |
|
| 39 |
- flags.StringVar(&opts.secret, "secret", "", "Set secret value needed to accept nodes into cluster") |
|
| 40 |
- flags.Int64Var(&opts.taskHistoryLimit, "task-history-limit", 10, "Task history retention limit") |
|
| 41 |
- flags.DurationVar(&opts.dispatcherHeartbeat, "dispatcher-heartbeat", time.Duration(5*time.Second), "Dispatcher heartbeat period") |
|
| 42 |
- flags.DurationVar(&opts.nodeCertExpiry, "cert-expiry", time.Duration(90*24*time.Hour), "Validity period for node certificates") |
|
| 36 |
+ flags := cmd.Flags() |
|
| 37 |
+ flags.Var(&opts.autoAccept, flagAutoAccept, "Auto acceptance policy (worker, manager or none)") |
|
| 38 |
+ flags.StringVar(&opts.secret, flagSecret, "", "Set secret value needed to accept nodes into cluster") |
|
| 39 |
+ flags.Int64Var(&opts.taskHistoryLimit, flagTaskHistoryLimit, 10, "Task history retention limit") |
|
| 40 |
+ flags.DurationVar(&opts.dispatcherHeartbeat, flagDispatcherHeartbeat, time.Duration(5*time.Second), "Dispatcher heartbeat period") |
|
| 41 |
+ flags.DurationVar(&opts.nodeCertExpiry, flagCertExpiry, time.Duration(90*24*time.Hour), "Validity period for node certificates") |
|
| 43 | 42 |
return cmd |
| 44 | 43 |
} |
| 45 | 44 |
|
| ... | ... |
@@ -69,14 +68,14 @@ func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts updateOpt |
| 69 | 69 |
func mergeSwarm(swarm *swarm.Swarm, flags *pflag.FlagSet) error {
|
| 70 | 70 |
spec := &swarm.Spec |
| 71 | 71 |
|
| 72 |
- if flags.Changed("auto-accept") {
|
|
| 73 |
- value := flags.Lookup("auto-accept").Value.(*AutoAcceptOption)
|
|
| 72 |
+ if flags.Changed(flagAutoAccept) {
|
|
| 73 |
+ value := flags.Lookup(flagAutoAccept).Value.(*AutoAcceptOption) |
|
| 74 | 74 |
spec.AcceptancePolicy.Policies = value.Policies(nil) |
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 | 77 |
var psecret *string |
| 78 |
- if flags.Changed("secret") {
|
|
| 79 |
- secret, _ := flags.GetString("secret")
|
|
| 78 |
+ if flags.Changed(flagSecret) {
|
|
| 79 |
+ secret, _ := flags.GetString(flagSecret) |
|
| 80 | 80 |
psecret = &secret |
| 81 | 81 |
} |
| 82 | 82 |
|
| ... | ... |
@@ -84,18 +83,18 @@ func mergeSwarm(swarm *swarm.Swarm, flags *pflag.FlagSet) error {
|
| 84 | 84 |
spec.AcceptancePolicy.Policies[i].Secret = psecret |
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 |
- if flags.Changed("task-history-limit") {
|
|
| 88 |
- spec.Orchestration.TaskHistoryRetentionLimit, _ = flags.GetInt64("task-history-limit")
|
|
| 87 |
+ if flags.Changed(flagTaskHistoryLimit) {
|
|
| 88 |
+ spec.Orchestration.TaskHistoryRetentionLimit, _ = flags.GetInt64(flagTaskHistoryLimit) |
|
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 |
- if flags.Changed("dispatcher-heartbeat") {
|
|
| 92 |
- if v, err := flags.GetDuration("dispatcher-heartbeat"); err == nil {
|
|
| 91 |
+ if flags.Changed(flagDispatcherHeartbeat) {
|
|
| 92 |
+ if v, err := flags.GetDuration(flagDispatcherHeartbeat); err == nil {
|
|
| 93 | 93 |
spec.Dispatcher.HeartbeatPeriod = uint64(v.Nanoseconds()) |
| 94 | 94 |
} |
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 |
- if flags.Changed("cert-expiry") {
|
|
| 98 |
- if v, err := flags.GetDuration("cert-expiry"); err == nil {
|
|
| 97 |
+ if flags.Changed(flagCertExpiry) {
|
|
| 98 |
+ if v, err := flags.GetDuration(flagCertExpiry); err == nil {
|
|
| 99 | 99 |
spec.CAConfig.NodeCertExpiry = v |
| 100 | 100 |
} |
| 101 | 101 |
} |