Make the CLI show defaults from the swarmkit defaults package

If no fields related to an update config or restart policy are
specified, these structs should not be created as part of the service,
to avoid hardcoding the current defaults.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
master
Aaron Lehmann 2017-03-30 18:35:04 -07:00 committed by Vincent Demeester
parent 4cde08da8e
commit d160d98970
2 changed files with 13 additions and 7 deletions

View File

@ -38,7 +38,10 @@ func NewListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts {
}
func (opts *ListOpts) String() string {
return fmt.Sprintf("%v", []string((*opts.values)))
if len(*opts.values) == 0 {
return ""
}
return fmt.Sprintf("%v", *opts.values)
}
// Set validates if needed the input value and adds it to the
@ -343,6 +346,9 @@ type NanoCPUs int64
// String returns the string format of the number
func (c *NanoCPUs) String() string {
if *c == 0 {
return ""
}
return big.NewRat(c.Value(), 1e9).FloatString(3)
}

View File

@ -93,12 +93,12 @@ func TestListOptsWithValidator(t *testing.T) {
// Re-using logOptsvalidator (used by MapOpts)
o := NewListOpts(logOptsValidator)
o.Set("foo")
if o.String() != "[]" {
t.Errorf("%s != []", o.String())
if o.String() != "" {
t.Errorf(`%s != ""`, o.String())
}
o.Set("foo=bar")
if o.String() != "[]" {
t.Errorf("%s != []", o.String())
if o.String() != "" {
t.Errorf(`%s != ""`, o.String())
}
o.Set("max-file=2")
if o.Len() != 1 {
@ -111,8 +111,8 @@ func TestListOptsWithValidator(t *testing.T) {
t.Error("o.Get(\"baz\") == true")
}
o.Delete("max-file=2")
if o.String() != "[]" {
t.Errorf("%s != []", o.String())
if o.String() != "" {
t.Errorf(`%s != ""`, o.String())
}
}