vendor/github.com/spf13/pflag/string_slice.go
changeset 251 1c52a0eeb952
parent 242 2a9ec03fe5a1
equal deleted inserted replaced
250:c040f992052f 251:1c52a0eeb952
    60 func (s *stringSliceValue) String() string {
    60 func (s *stringSliceValue) String() string {
    61 	str, _ := writeAsCSV(*s.value)
    61 	str, _ := writeAsCSV(*s.value)
    62 	return "[" + str + "]"
    62 	return "[" + str + "]"
    63 }
    63 }
    64 
    64 
       
    65 func (s *stringSliceValue) Append(val string) error {
       
    66 	*s.value = append(*s.value, val)
       
    67 	return nil
       
    68 }
       
    69 
       
    70 func (s *stringSliceValue) Replace(val []string) error {
       
    71 	*s.value = val
       
    72 	return nil
       
    73 }
       
    74 
       
    75 func (s *stringSliceValue) GetSlice() []string {
       
    76 	return *s.value
       
    77 }
       
    78 
    65 func stringSliceConv(sval string) (interface{}, error) {
    79 func stringSliceConv(sval string) (interface{}, error) {
    66 	sval = sval[1 : len(sval)-1]
    80 	sval = sval[1 : len(sval)-1]
    67 	// An empty string would cause a slice with one (empty) string
    81 	// An empty string would cause a slice with one (empty) string
    68 	if len(sval) == 0 {
    82 	if len(sval) == 0 {
    69 		return []string{}, nil
    83 		return []string{}, nil
    82 
    96 
    83 // StringSliceVar defines a string flag with specified name, default value, and usage string.
    97 // StringSliceVar defines a string flag with specified name, default value, and usage string.
    84 // The argument p points to a []string variable in which to store the value of the flag.
    98 // The argument p points to a []string variable in which to store the value of the flag.
    85 // Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
    99 // Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
    86 // For example:
   100 // For example:
    87 //   --ss="v1,v2" -ss="v3"
   101 //   --ss="v1,v2" --ss="v3"
    88 // will result in
   102 // will result in
    89 //   []string{"v1", "v2", "v3"}
   103 //   []string{"v1", "v2", "v3"}
    90 func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) {
   104 func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) {
    91 	f.VarP(newStringSliceValue(value, p), name, "", usage)
   105 	f.VarP(newStringSliceValue(value, p), name, "", usage)
    92 }
   106 }
    98 
   112 
    99 // StringSliceVar defines a string flag with specified name, default value, and usage string.
   113 // StringSliceVar defines a string flag with specified name, default value, and usage string.
   100 // The argument p points to a []string variable in which to store the value of the flag.
   114 // The argument p points to a []string variable in which to store the value of the flag.
   101 // Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
   115 // Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
   102 // For example:
   116 // For example:
   103 //   --ss="v1,v2" -ss="v3"
   117 //   --ss="v1,v2" --ss="v3"
   104 // will result in
   118 // will result in
   105 //   []string{"v1", "v2", "v3"}
   119 //   []string{"v1", "v2", "v3"}
   106 func StringSliceVar(p *[]string, name string, value []string, usage string) {
   120 func StringSliceVar(p *[]string, name string, value []string, usage string) {
   107 	CommandLine.VarP(newStringSliceValue(value, p), name, "", usage)
   121 	CommandLine.VarP(newStringSliceValue(value, p), name, "", usage)
   108 }
   122 }
   114 
   128 
   115 // StringSlice defines a string flag with specified name, default value, and usage string.
   129 // StringSlice defines a string flag with specified name, default value, and usage string.
   116 // The return value is the address of a []string variable that stores the value of the flag.
   130 // The return value is the address of a []string variable that stores the value of the flag.
   117 // Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
   131 // Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
   118 // For example:
   132 // For example:
   119 //   --ss="v1,v2" -ss="v3"
   133 //   --ss="v1,v2" --ss="v3"
   120 // will result in
   134 // will result in
   121 //   []string{"v1", "v2", "v3"}
   135 //   []string{"v1", "v2", "v3"}
   122 func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string {
   136 func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string {
   123 	p := []string{}
   137 	p := []string{}
   124 	f.StringSliceVarP(&p, name, "", value, usage)
   138 	f.StringSliceVarP(&p, name, "", value, usage)
   134 
   148 
   135 // StringSlice defines a string flag with specified name, default value, and usage string.
   149 // StringSlice defines a string flag with specified name, default value, and usage string.
   136 // The return value is the address of a []string variable that stores the value of the flag.
   150 // The return value is the address of a []string variable that stores the value of the flag.
   137 // Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
   151 // Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
   138 // For example:
   152 // For example:
   139 //   --ss="v1,v2" -ss="v3"
   153 //   --ss="v1,v2" --ss="v3"
   140 // will result in
   154 // will result in
   141 //   []string{"v1", "v2", "v3"}
   155 //   []string{"v1", "v2", "v3"}
   142 func StringSlice(name string, value []string, usage string) *[]string {
   156 func StringSlice(name string, value []string, usage string) *[]string {
   143 	return CommandLine.StringSliceP(name, "", value, usage)
   157 	return CommandLine.StringSliceP(name, "", value, usage)
   144 }
   158 }