...

Source file src/github.com/docker/cli/opts/quotedstring.go

Documentation: github.com/docker/cli/opts

     1  package opts
     2  
     3  // QuotedString is a string that may have extra quotes around the value. The
     4  // quotes are stripped from the value.
     5  type QuotedString struct {
     6  	value *string
     7  }
     8  
     9  // Set sets a new value
    10  func (s *QuotedString) Set(val string) error {
    11  	*s.value = trimQuotes(val)
    12  	return nil
    13  }
    14  
    15  // Type returns the type of the value
    16  func (s *QuotedString) Type() string {
    17  	return "string"
    18  }
    19  
    20  func (s *QuotedString) String() string {
    21  	return *s.value
    22  }
    23  
    24  func trimQuotes(value string) string {
    25  	if len(value) < 2 {
    26  		return value
    27  	}
    28  	lastIndex := len(value) - 1
    29  	for _, char := range []byte{'\'', '"'} {
    30  		if value[0] == char && value[lastIndex] == char {
    31  			return value[1:lastIndex]
    32  		}
    33  	}
    34  	return value
    35  }
    36  
    37  // NewQuotedString returns a new quoted string option
    38  func NewQuotedString(value *string) *QuotedString {
    39  	return &QuotedString{value: value}
    40  }
    41  

View as plain text