diff options
author | Tianon Gravi <admwiggin@gmail.com> | 2022-02-16 12:38:57 -0800 |
---|---|---|
committer | Tianon Gravi <admwiggin@gmail.com> | 2022-02-16 12:54:06 -0800 |
commit | c79a169a35f8ee0ecb66cfcffab4b0bd2c77f996 (patch) | |
tree | c8e80c08e53769bda0ea282da54664ebd146d83a /opts | |
parent | c94596abc975f7cf6a09cab0ef9b32aaf1f72ae7 (diff) | |
download | docker-c79a169a35f8ee0ecb66cfcffab4b0bd2c77f996.tar.gz |
Remove opts.QuotedString implementation
This was originally added to solve a CLI usability issue related to `docker-machine` and `docker` (explicitly *not* `dockerd`) -- the "docker/cli" repository has a separate copy of this entire `opts` package, so isn't even using this implementation.
Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
Diffstat (limited to 'opts')
-rw-r--r-- | opts/quotedstring.go | 41 | ||||
-rw-r--r-- | opts/quotedstring_test.go | 34 |
2 files changed, 0 insertions, 75 deletions
diff --git a/opts/quotedstring.go b/opts/quotedstring.go deleted file mode 100644 index 34f30971e4..0000000000 --- a/opts/quotedstring.go +++ /dev/null @@ -1,41 +0,0 @@ -package opts // import "github.com/docker/docker/opts" - -// QuotedString is a string that may have extra quotes around the value. The -// quotes are stripped from the value. -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 (s *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 -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 fc7b7747b1..0000000000 --- a/opts/quotedstring_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package opts // import "github.com/docker/docker/opts" - -import ( - "testing" - - "gotest.tools/v3/assert" - is "gotest.tools/v3/assert/cmp" -) - -func TestQuotedStringSetWithQuotes(t *testing.T) { - value := "" - qs := NewQuotedString(&value) - assert.Check(t, qs.Set(`"something"`)) - assert.Check(t, is.Equal("something", qs.String())) - assert.Check(t, is.Equal("something", value)) -} - -func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) { - qs := NewQuotedString(new(string)) - assert.Check(t, qs.Set(`"something'`)) - assert.Check(t, is.Equal(`"something'`, qs.String())) -} - -func TestQuotedStringSetWithNoQuotes(t *testing.T) { - qs := NewQuotedString(new(string)) - assert.Check(t, qs.Set("something")) - assert.Check(t, is.Equal("something", qs.String())) -} - -func TestQuotedStringEmptyOrSingleCharString(t *testing.T) { - qs := NewQuotedString(new(string)) - assert.Check(t, qs.Set("")) - assert.Check(t, qs.Set("'")) -} |