Skip to content

Commit d8bab71

Browse files
committed
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]: moby/moby@1ba1138 [moby@6200002]: moby/moby@6200002 Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 193db8e) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 36d9523 commit d8bab71

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

opts/opts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ func (opts *ListOpts) Set(value string) error {
6060
}
6161

6262
// Delete removes the specified element from the slice.
63+
//
64+
// Deprecated: this method is no longer used and will be removed in the next release.
6365
func (opts *ListOpts) Delete(key string) {
6466
for i, k := range *opts.values {
6567
if k == key {

opts/opts_test.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,14 @@ func TestListOptsWithoutValidator(t *testing.T) {
142142
if o.Get("baz") {
143143
t.Error(`o.Get("baz") == true`)
144144
}
145-
o.Delete("foo")
146-
if o.String() != "[bar bar]" {
147-
t.Errorf("%s != [bar bar]", o.String())
145+
if listOpts := o.GetSlice(); len(listOpts) != 3 || listOpts[0] != "foo" || listOpts[1] != "bar" || listOpts[2] != "bar" {
146+
t.Errorf("Expected [[foo bar bar]], got [%v]", listOpts)
148147
}
149-
if listOpts := o.GetAll(); len(listOpts) != 2 || listOpts[0] != "bar" || listOpts[1] != "bar" {
150-
t.Errorf("Expected [[bar bar]], got [%v]", listOpts)
148+
if listOpts := o.GetAll(); len(listOpts) != 3 || listOpts[0] != "foo" || listOpts[1] != "bar" || listOpts[2] != "bar" {
149+
t.Errorf("Expected [[foo bar bar]], got [%v]", listOpts)
151150
}
152-
if listOpts := o.GetSlice(); len(listOpts) != 2 || listOpts[0] != "bar" || listOpts[1] != "bar" {
153-
t.Errorf("Expected [[bar bar]], got [%v]", listOpts)
154-
}
155-
if mapListOpts := o.GetMap(); len(mapListOpts) != 1 {
156-
t.Errorf("Expected [map[bar:{}]], got [%v]", mapListOpts)
151+
if mapListOpts := o.GetMap(); len(mapListOpts) != 2 {
152+
t.Errorf("Expected [map[bar:{} foo:{}]], got [%v]", mapListOpts)
157153
}
158154
}
159155

@@ -186,9 +182,8 @@ func TestListOptsWithValidator(t *testing.T) {
186182
if o.Get("baz") {
187183
t.Error(`o.Get("baz") == true`)
188184
}
189-
o.Delete("valid-option2=2")
190-
if o.String() != "" {
191-
t.Errorf(`%s != ""`, o.String())
185+
if expected := "[valid-option2=2]"; o.String() != expected {
186+
t.Errorf(`%s != %q`, o.String(), expected)
192187
}
193188
}
194189

0 commit comments

Comments
 (0)