From 193db8ec4171e17f2ef443ccc3ad77965f9629d8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 13 Oct 2025 11:47:39 +0200 Subject: [PATCH] opts: deprecate ListOpts.Delete() This method was added as part of a refactor in [moby@1ba1138], at which time it was used to delete original values for "--host" and "--volume" after normalizing. This beccame redundant in [moby@6200002], which added specialized options that used a validate function, which both validated and normalized inputs. It's no longer used, so let's mark it deprecated so that we can remove it. [moby@1ba1138]: https://github.com/moby/moby/commit/1ba11384bf82f824b0efbab31aaca439cfba1b4f [moby@6200002]: https://github.com/moby/moby/commit/6200002669874f3314856527fecd0c004060913c Signed-off-by: Sebastiaan van Stijn --- opts/opts.go | 2 ++ opts/opts_test.go | 17 ++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/opts/opts.go b/opts/opts.go index 84e679912..94afa8e16 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -61,6 +61,8 @@ func (opts *ListOpts) Set(value string) error { } // Delete removes the specified element from the slice. +// +// Deprecated: this method is no longer used and will be removed in the next release. func (opts *ListOpts) Delete(key string) { for i, k := range *opts.values { if k == key { diff --git a/opts/opts_test.go b/opts/opts_test.go index 958495075..e978c2ea8 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -141,15 +141,11 @@ func TestListOptsWithoutValidator(t *testing.T) { if o.Get("baz") { t.Error(`o.Get("baz") == true`) } - o.Delete("foo") - if o.String() != "[bar bar]" { - t.Errorf("%s != [bar bar]", o.String()) + if listOpts := o.GetSlice(); len(listOpts) != 3 || listOpts[0] != "foo" || listOpts[1] != "bar" || listOpts[2] != "bar" { + t.Errorf("Expected [[foo 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) - } - if mapListOpts := o.GetMap(); len(mapListOpts) != 1 { - t.Errorf("Expected [map[bar:{}]], got [%v]", mapListOpts) + if mapListOpts := o.GetMap(); len(mapListOpts) != 2 { + t.Errorf("Expected [map[bar:{} foo:{}]], got [%v]", mapListOpts) } } @@ -182,9 +178,8 @@ func TestListOptsWithValidator(t *testing.T) { if o.Get("baz") { t.Error(`o.Get("baz") == true`) } - o.Delete("valid-option2=2") - if o.String() != "" { - t.Errorf(`%s != ""`, o.String()) + if expected := "[valid-option2=2]"; o.String() != expected { + t.Errorf(`%s != %q`, o.String(), expected) } }