diff --git a/components/cli/opts/opts.go b/components/cli/opts/opts.go index 8c82960c20..f76f308051 100644 --- a/components/cli/opts/opts.go +++ b/components/cli/opts/opts.go @@ -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) } diff --git a/components/cli/opts/opts_test.go b/components/cli/opts/opts_test.go index e137127156..c1e7735b58 100644 --- a/components/cli/opts/opts_test.go +++ b/components/cli/opts/opts_test.go @@ -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()) } }