github.com/puellanivis/breton@v0.2.16/lib/gnuflag/string.go (about)

     1  package gnuflag
     2  
     3  // -- string Value
     4  type stringValue string
     5  
     6  func (s *stringValue) Set(val string) error {
     7  	*s = stringValue(val)
     8  	return nil
     9  }
    10  
    11  func (s stringValue) Get() interface{} { return string(s) }
    12  
    13  func (s stringValue) String() string { return string(s) }
    14  
    15  // String defines a string flag with specified name, and usage string.
    16  // The return value is the address of a string variable that stores the value of the flag.
    17  func (f *FlagSet) String(name string, usage string, options ...Option) *string {
    18  	p := new(string)
    19  	if err := f.Var((*stringValue)(p), name, usage, options...); err != nil {
    20  		panic(err)
    21  	}
    22  	return p
    23  }
    24  
    25  // String defines a string flag with specified name, and usage string.
    26  // The return value is the address of a string variable that stores the value of the flag.
    27  func String(name string, usage string, options ...Option) *string {
    28  	return CommandLine.String(name, usage, options...)
    29  }