Browse code

Fix misleading default for `--replicas`

This fix tries to address the issue raised in 29291 where
the output of `--replicas` in `service create/update`:
```
--replicas uint Number of tasks (default none)
```
is misleading. User might incorrectly assume the number of replicas
would be `0` (`none`) by default, while the actual default is `1`.

The issue comes from the fact that some of the default values are
from daemon and it is not possible for client to find out the default
value.

In this case, it might be better to just simply not displaying `(default none)`.

This fix returns "" for `Uint64Opt` so that `(default none)` is hidden.

In addition to `--replicas`, this fix also changes
`--restart-delay`, `--restart-max-attempts`, `--stop-grace-period`,
`--health-interval`, `--health-timeout`, and `--restart-window`
in a similiar fashion.

New Output:
```
--health-interval duration Time between running the check (ns|us|ms|s|m|h)
--health-timeout duration Maximum time to allow one check to run (ns|us|ms|s|m|h)
...
--replicas uint Number of tasks
...
--restart-delay duration Delay between restart attempts (ns|us|ms|s|m|h)
--restart-max-attempts uint Maximum number of restarts before giving up
--restart-window duration Window used to evaluate the restart policy (ns|us|ms|s|m|h)
...
--stop-grace-period duration Time to wait before force killing a container (ns|us|ms|s|m|h)
```

The docs has been updated. Note the docs for help output of `service create/update`
is out of sync with the current master. This fix replace with the update-to-date
help output.

This fix fixes 29291.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2016/12/15 23:12:33
Showing 4 changed files
... ...
@@ -84,7 +84,7 @@ func (d *DurationOpt) String() string {
84 84
 	if d.value != nil {
85 85
 		return d.value.String()
86 86
 	}
87
-	return "none"
87
+	return ""
88 88
 }
89 89
 
90 90
 // Value returns the time.Duration
... ...
@@ -114,7 +114,7 @@ func (i *Uint64Opt) String() string {
114 114
 	if i.value != nil {
115 115
 		return fmt.Sprintf("%v", *i.value)
116 116
 	}
117
-	return "none"
117
+	return ""
118 118
 }
119 119
 
120 120
 // Value returns the uint64
... ...
@@ -59,7 +59,7 @@ func TestUint64OptString(t *testing.T) {
59 59
 	assert.Equal(t, opt.String(), "2345678")
60 60
 
61 61
 	opt = Uint64Opt{}
62
-	assert.Equal(t, opt.String(), "none")
62
+	assert.Equal(t, opt.String(), "")
63 63
 }
64 64
 
65 65
 func TestUint64OptSetAndValue(t *testing.T) {
... ...
@@ -31,9 +31,9 @@ Options:
31 31
       --env-file list                    Read in a file of environment variables (default [])
32 32
       --group list                       Set one or more supplementary user groups for the container (default [])
33 33
       --health-cmd string                Command to run to check health
34
-      --health-interval duration         Time between running the check (ns|us|ms|s|m|h) (default none)
34
+      --health-interval duration         Time between running the check (ns|us|ms|s|m|h)
35 35
       --health-retries int               Consecutive failures needed to report unhealthy
36
-      --health-timeout duration          Maximum time to allow one check to run (ns|us|ms|s|m|h) (default none)
36
+      --health-timeout duration          Maximum time to allow one check to run (ns|us|ms|s|m|h)
37 37
       --help                             Print usage
38 38
       --host list                        Set one or more custom host-to-IP mappings (host:ip) (default [])
39 39
       --hostname string                  Container hostname
... ...
@@ -47,16 +47,16 @@ Options:
47 47
       --name string                      Service name
48 48
       --network list                     Network attachments (default [])
49 49
       --no-healthcheck                   Disable any container-specified HEALTHCHECK
50
-  -p, --publish list                     Publish a port as a node port (default [])
51
-      --replicas uint                    Number of tasks (default none)
50
+  -p, --publish port                     Publish a port as a node port
51
+      --replicas uint                    Number of tasks
52 52
       --reserve-cpu decimal              Reserve CPUs (default 0.000)
53 53
       --reserve-memory bytes             Reserve Memory (default 0 B)
54 54
       --restart-condition string         Restart when condition is met (none, on-failure, or any)
55
-      --restart-delay duration           Delay between restart attempts (ns|us|ms|s|m|h) (default none)
56
-      --restart-max-attempts uint        Maximum number of restarts before giving up (default none)
57
-      --restart-window duration          Window used to evaluate the restart policy (ns|us|ms|s|m|h) (default none)
58
-      --secret value                     Specify secrets to expose to the service (default [])
59
-      --stop-grace-period duration       Time to wait before force killing a container (ns|us|ms|s|m|h) (default none)
55
+      --restart-delay duration           Delay between restart attempts (ns|us|ms|s|m|h)
56
+      --restart-max-attempts uint        Maximum number of restarts before giving up
57
+      --restart-window duration          Window used to evaluate the restart policy (ns|us|ms|s|m|h)
58
+      --secret secret                    Specify secrets to expose to the service
59
+      --stop-grace-period duration       Time to wait before force killing a container (ns|us|ms|s|m|h)
60 60
   -t, --tty                              Allocate a pseudo-TTY
61 61
       --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
62 62
       --update-failure-action string     Action on update failure (pause|continue) (default "pause")
... ...
@@ -39,9 +39,9 @@ Options:
39 39
       --group-add list                   Add an additional supplementary user group to the container (default [])
40 40
       --group-rm list                    Remove a previously added supplementary user group from the container (default [])
41 41
       --health-cmd string                Command to run to check health
42
-      --health-interval duration         Time between running the check (ns|us|ms|s|m|h) (default none)
42
+      --health-interval duration         Time between running the check (ns|us|ms|s|m|h)
43 43
       --health-retries int               Consecutive failures needed to report unhealthy
44
-      --health-timeout duration          Maximum time to allow one check to run (ns|us|ms|s|m|h) (default none)
44
+      --health-timeout duration          Maximum time to allow one check to run (ns|us|ms|s|m|h)
45 45
       --help                             Print usage
46 46
       --host-add list                    Add or update a custom host-to-IP mapping (host:ip) (default [])
47 47
       --host-rm list                     Remove a custom host-to-IP mapping (host:ip) (default [])
... ...
@@ -56,19 +56,19 @@ Options:
56 56
       --mount-add mount                  Add or update a mount on a service
57 57
       --mount-rm list                    Remove a mount by its target path (default [])
58 58
       --no-healthcheck                   Disable any container-specified HEALTHCHECK
59
-      --publish-add list                 Add or update a published port (default [])
60
-      --publish-rm list                  Remove a published port by its target port (default [])
61
-      --replicas uint                    Number of tasks (default none)
59
+      --publish-add port                 Add or update a published port
60
+      --publish-rm port                  Remove a published port by its target port
61
+      --replicas uint                    Number of tasks
62 62
       --reserve-cpu decimal              Reserve CPUs (default 0.000)
63 63
       --reserve-memory bytes             Reserve Memory (default 0 B)
64 64
       --restart-condition string         Restart when condition is met (none, on-failure, or any)
65
-      --restart-delay duration           Delay between restart attempts (ns|us|ms|s|m|h) (default none)
66
-      --restart-max-attempts uint        Maximum number of restarts before giving up (default none)
67
-      --restart-window duration          Window used to evaluate the restart policy (ns|us|ms|s|m|h) (default none)
65
+      --restart-delay duration           Delay between restart attempts (ns|us|ms|s|m|h)
66
+      --restart-max-attempts uint        Maximum number of restarts before giving up
67
+      --restart-window duration          Window used to evaluate the restart policy (ns|us|ms|s|m|h)
68 68
       --rollback                         Rollback to previous specification
69
-      --secret-add list                  Add a secret (default [])
69
+      --secret-add secret                Add or update a secret on a service
70 70
       --secret-rm list                   Remove a secret (default [])
71
-      --stop-grace-period duration       Time to wait before force killing a container (ns|us|ms|s|m|h) (default none)
71
+      --stop-grace-period duration       Time to wait before force killing a container (ns|us|ms|s|m|h)
72 72
   -t, --tty                              Allocate a pseudo-TTY
73 73
       --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
74 74
       --update-failure-action string     Action on update failure (pause|continue) (default "pause")