From 0c07d81a039b4e2a12202aba2bd35b5201340673 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 18 Aug 2025 17:42:31 +0200 Subject: [PATCH 1/4] opts: remove deprecated QuotedString This type is no longer used, and was deprecated in 187a942a88913d31a1c9e511b920282222e75db0 Signed-off-by: Sebastiaan van Stijn --- opts/quotedstring.go | 44 --------------------------------------- opts/quotedstring_test.go | 40 ----------------------------------- 2 files changed, 84 deletions(-) delete mode 100644 opts/quotedstring.go delete mode 100644 opts/quotedstring_test.go diff --git a/opts/quotedstring.go b/opts/quotedstring.go deleted file mode 100644 index d1d8b09a1fec..000000000000 --- a/opts/quotedstring.go +++ /dev/null @@ -1,44 +0,0 @@ -package opts - -// QuotedString is a string that may have extra quotes around the value. The -// quotes are stripped from the value. -// -// Deprecated: This option type is no longer used and will be removed in the next release. -type QuotedString struct { - value *string -} - -// Set sets a new value -func (s *QuotedString) Set(val string) error { - *s.value = trimQuotes(val) - return nil -} - -// Type returns the type of the value -func (*QuotedString) Type() string { - return "string" -} - -func (s *QuotedString) String() string { - return *s.value -} - -func trimQuotes(value string) string { - if len(value) < 2 { - return value - } - lastIndex := len(value) - 1 - for _, char := range []byte{'\'', '"'} { - if value[0] == char && value[lastIndex] == char { - return value[1:lastIndex] - } - } - return value -} - -// NewQuotedString returns a new quoted string option -// -// Deprecated: This option type is no longer used and will be removed in the next release. -func NewQuotedString(value *string) *QuotedString { - return &QuotedString{value: value} -} diff --git a/opts/quotedstring_test.go b/opts/quotedstring_test.go deleted file mode 100644 index f56868b1c63e..000000000000 --- a/opts/quotedstring_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package opts - -import ( - "testing" - - "gotest.tools/v3/assert" - is "gotest.tools/v3/assert/cmp" -) - -func TestQuotedStringSetWithQuotes(t *testing.T) { - value := "" - qs := NewQuotedString(&value) - assert.NilError(t, qs.Set(`"something"`)) - assert.Check(t, is.Equal("something", qs.String())) - assert.Check(t, is.Equal("something", value)) -} - -func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) { - value := "" - qs := NewQuotedString(&value) - assert.NilError(t, qs.Set(`"something'`)) - assert.Check(t, is.Equal(`"something'`, qs.String())) -} - -func TestQuotedStringSetWithNoQuotes(t *testing.T) { - value := "" - qs := NewQuotedString(&value) - assert.NilError(t, qs.Set("something")) - assert.Check(t, is.Equal("something", qs.String())) -} - -func TestQuotedStringShort(t *testing.T) { - value := "" - qs := NewQuotedString(&value) - assert.NilError(t, qs.Set(`"`)) - assert.Check(t, is.Equal(`"`, qs.String())) - - assert.NilError(t, qs.Set(`'`)) - assert.Check(t, is.Equal(`'`, qs.String())) -} From 15f3e910d16d3037610c3ddbd094ca267313f207 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 18 Aug 2025 18:40:05 +0200 Subject: [PATCH 2/4] opts: remove deprecated ValidateHost This function is no longer used, and was deprecated in d0ac0acff01dc8834e7829679c3183e59d9af247. Signed-off-by: Sebastiaan van Stijn --- opts/hosts.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/opts/hosts.go b/opts/hosts.go index 87e1a1da755b..dcbbb7e78166 100644 --- a/opts/hosts.go +++ b/opts/hosts.go @@ -32,23 +32,6 @@ const ( hostGatewayName = "host-gateway" ) -// ValidateHost validates that the specified string is a valid host and returns it. -// -// Deprecated: this function is no longer used, and will be removed in the next release. -func ValidateHost(val string) (string, error) { - host := strings.TrimSpace(val) - // The empty string means default and is not handled by parseDockerDaemonHost - if host != "" { - _, err := parseDockerDaemonHost(host) - if err != nil { - return val, err - } - } - // Note: unlike most flag validators, we don't return the mutated value here - // we need to know what the user entered later (using ParseHost) to adjust for TLS - return val, nil -} - // ParseHost and set defaults for a Daemon host string func ParseHost(defaultToTLS bool, val string) (string, error) { host := strings.TrimSpace(val) From a056cc61644c2b388ed4071603c75c966dfb3e0a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 18 Aug 2025 18:43:13 +0200 Subject: [PATCH 3/4] opts: remove deprecated ListOpts.GetAll It's no longer used and replaced by `ListOpts.GetSlice`. It was deprecated in 5215b1eca41e5cd0e22b3bd4e4768c053cba09c5 Signed-off-by: Sebastiaan van Stijn --- opts/opts.go | 7 ------- opts/opts_test.go | 4 ---- 2 files changed, 11 deletions(-) diff --git a/opts/opts.go b/opts/opts.go index e7a97a573ecd..472188d8bcf9 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -79,13 +79,6 @@ func (opts *ListOpts) GetMap() map[string]struct{} { return ret } -// GetAll returns the values of slice. -// -// Deprecated: use [ListOpts.GetSlice] instead. This method will be removed in a future release. -func (opts *ListOpts) GetAll() []string { - return *opts.values -} - // GetSlice returns the values of slice. // // It implements [cobra.SliceValue] to allow shell completion to be provided diff --git a/opts/opts_test.go b/opts/opts_test.go index 7dc87cad9e83..c5908e8f151a 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -112,7 +112,6 @@ func TestMapOpts(t *testing.T) { } } -//nolint:gocyclo // ignore "cyclomatic complexity 17 is too high" func TestListOptsWithoutValidator(t *testing.T) { o := NewListOpts(nil) err := o.Set("foo") @@ -146,9 +145,6 @@ func TestListOptsWithoutValidator(t *testing.T) { if o.String() != "[bar bar]" { t.Errorf("%s != [bar bar]", o.String()) } - if listOpts := o.GetAll(); len(listOpts) != 2 || listOpts[0] != "bar" || listOpts[1] != "bar" { - t.Errorf("Expected [[bar bar]], got [%v]", listOpts) - } if listOpts := o.GetSlice(); len(listOpts) != 2 || listOpts[0] != "bar" || listOpts[1] != "bar" { t.Errorf("Expected [[bar bar]], got [%v]", listOpts) } From 5934553198cdb980e909b047b994604233f2a55d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 18 Aug 2025 18:47:45 +0200 Subject: [PATCH 4/4] opts: remove deprecated NewNamedListOptsRef, NewNamedMapOpts These were deprecated in 6f0c66c152e2e64ad38e75a560449a292cc28f7a and are no longer used. This removes the deprecated: - `NewNamedListOptsRef` - `NewNamedMapOpts` - `NamedListOpts` - `NamedMapOpts` - `NamedOption` Signed-off-by: Sebastiaan van Stijn --- opts/opts.go | 66 ----------------------------------------------- opts/opts_test.go | 32 ----------------------- 2 files changed, 98 deletions(-) diff --git a/opts/opts.go b/opts/opts.go index 472188d8bcf9..6ea218130454 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -125,43 +125,6 @@ func (opts *ListOpts) WithValidator(validator ValidatorFctType) *ListOpts { return opts } -// NamedOption is an interface that list and map options -// with names implement. -// -// Deprecated: NamedOption is no longer used and will be removed in the next release. -type NamedOption interface { - Name() string -} - -// NamedListOpts is a ListOpts with a configuration name. -// This struct is useful to keep reference to the assigned -// field name in the internal configuration struct. -// -// Deprecated: NamedListOpts is no longer used and will be removed in the next release. -type NamedListOpts struct { - name string - ListOpts -} - -var _ NamedOption = &NamedListOpts{} - -// NewNamedListOptsRef creates a reference to a new NamedListOpts struct. -// -// Deprecated: NewNamedListOptsRef is no longer used and will be removed in the next release. -func NewNamedListOptsRef(name string, values *[]string, validator ValidatorFctType) *NamedListOpts { - return &NamedListOpts{ - name: name, - ListOpts: *NewListOptsRef(values, validator), - } -} - -// Name returns the name of the NamedListOpts in the configuration. -// -// Deprecated: NamedListOpts is no longer used and will be removed in the next release. -func (o *NamedListOpts) Name() string { - return o.name -} - // MapOpts holds a map of values and a validation function. type MapOpts struct { values map[string]string @@ -208,35 +171,6 @@ func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts { } } -// NamedMapOpts is a MapOpts struct with a configuration name. -// This struct is useful to keep reference to the assigned -// field name in the internal configuration struct. -// -// Deprecated: NamedMapOpts is no longer used and will be removed in the next release. -type NamedMapOpts struct { - name string - MapOpts -} - -var _ NamedOption = &NamedMapOpts{} - -// NewNamedMapOpts creates a reference to a new NamedMapOpts struct. -// -// Deprecated: NamedMapOpts is no longer used and will be removed in the next release. -func NewNamedMapOpts(name string, values map[string]string, validator ValidatorFctType) *NamedMapOpts { - return &NamedMapOpts{ - name: name, - MapOpts: *NewMapOpts(values, validator), - } -} - -// Name returns the name of the NamedMapOpts in the configuration. -// -// Deprecated: NamedMapOpts is no longer used and will be removed in the next release. -func (o *NamedMapOpts) Name() string { - return o.name -} - // ValidatorFctType defines a validator function that returns a validated string and/or an error. type ValidatorFctType func(val string) (string, error) diff --git a/opts/opts_test.go b/opts/opts_test.go index c5908e8f151a..39e7fdea43c1 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -360,38 +360,6 @@ func sampleValidator(val string) (string, error) { return "", fmt.Errorf("invalid key %s", k) } -func TestNamedListOpts(t *testing.T) { - var v []string - o := NewNamedListOptsRef("foo-name", &v, nil) - - o.Set("foo") - if o.String() != "[foo]" { - t.Errorf("%s != [foo]", o.String()) - } - if o.Name() != "foo-name" { - t.Errorf("%s != foo-name", o.Name()) - } - if len(v) != 1 { - t.Errorf("expected foo to be in the values, got %v", v) - } -} - -func TestNamedMapOpts(t *testing.T) { - tmpMap := make(map[string]string) - o := NewNamedMapOpts("max-name", tmpMap, nil) - - o.Set("max-size=1") - if o.String() != "map[max-size:1]" { - t.Errorf("%s != [map[max-size:1]", o.String()) - } - if o.Name() != "max-name" { - t.Errorf("%s != max-name", o.Name()) - } - if _, exist := tmpMap["max-size"]; !exist { - t.Errorf("expected map-size to be in the values, got %v", tmpMap) - } -} - func TestValidateMACAddress(t *testing.T) { if _, err := ValidateMACAddress(`92:d0:c6:0a:29:33`); err != nil { t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:29:33`) got %s", err)