diff --git a/opts/quotedstring.go b/opts/quotedstring.go index 8ddeee8085..fb1e5374bc 100644 --- a/opts/quotedstring.go +++ b/opts/quotedstring.go @@ -2,11 +2,13 @@ package opts // QuotedString is a string that may have extra quotes around the value. The // quotes are stripped from the value. -type QuotedString string +type QuotedString struct { + value *string +} // Set sets a new value func (s *QuotedString) Set(val string) error { - *s = QuotedString(trimQuotes(val)) + *s.value = trimQuotes(val) return nil } @@ -16,7 +18,7 @@ func (s *QuotedString) Type() string { } func (s *QuotedString) String() string { - return string(*s) + return string(*s.value) } func trimQuotes(value string) string { @@ -28,3 +30,8 @@ func trimQuotes(value string) string { } 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 index a508b9d210..0ebf04bbe0 100644 --- a/opts/quotedstring_test.go +++ b/opts/quotedstring_test.go @@ -6,19 +6,23 @@ import ( ) func TestQuotedStringSetWithQuotes(t *testing.T) { - qs := QuotedString("") + value := "" + qs := NewQuotedString(&value) assert.NilError(t, qs.Set("\"something\"")) assert.Equal(t, qs.String(), "something") + assert.Equal(t, value, "something") } func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) { - qs := QuotedString("") + value := "" + qs := NewQuotedString(&value) assert.NilError(t, qs.Set("\"something'")) assert.Equal(t, qs.String(), "\"something'") } func TestQuotedStringSetWithNoQuotes(t *testing.T) { - qs := QuotedString("") + value := "" + qs := NewQuotedString(&value) assert.NilError(t, qs.Set("something")) assert.Equal(t, qs.String(), "something") }