package pflagimport ()// -- stringSlice Valuetype stringSliceValue struct { value *[]string changed bool}func newStringSliceValue( []string, *[]string) *stringSliceValue { := new(stringSliceValue) .value = *.value = return}func readAsCSV( string) ([]string, error) {if == "" {return []string{}, nil } := strings.NewReader() := csv.NewReader()return .Read()}func writeAsCSV( []string) (string, error) { := &bytes.Buffer{} := csv.NewWriter() := .Write()if != nil {return"", } .Flush()returnstrings.TrimSuffix(.String(), "\n"), nil}func ( *stringSliceValue) ( string) error { , := readAsCSV()if != nil {return }if !.changed { *.value = } else { *.value = append(*.value, ...) } .changed = truereturnnil}func ( *stringSliceValue) () string {return"stringSlice"}func ( *stringSliceValue) () string { , := writeAsCSV(*.value)return"[" + + "]"}func ( *stringSliceValue) ( string) error { *.value = append(*.value, )returnnil}func ( *stringSliceValue) ( []string) error { *.value = returnnil}func ( *stringSliceValue) () []string {return *.value}func stringSliceConv( string) (interface{}, error) { = [1 : len()-1]// An empty string would cause a slice with one (empty) stringiflen() == 0 {return []string{}, nil }returnreadAsCSV()}// GetStringSlice return the []string value of a flag with the given namefunc ( *FlagSet) ( string) ([]string, error) { , := .getFlagType(, "stringSlice", stringSliceConv)if != nil {return []string{}, }return .([]string), nil}// StringSliceVar defines a string flag with specified name, default value, and usage string.// The argument p points to a []string variable in which to store the value of the flag.// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.// For example:// --ss="v1,v2" --ss="v3"// will result in// []string{"v1", "v2", "v3"}func ( *FlagSet) ( *[]string, string, []string, string) { .VarP(newStringSliceValue(, ), , "", )}// StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.func ( *FlagSet) ( *[]string, , string, []string, string) { .VarP(newStringSliceValue(, ), , , )}// StringSliceVar defines a string flag with specified name, default value, and usage string.// The argument p points to a []string variable in which to store the value of the flag.// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.// For example:// --ss="v1,v2" --ss="v3"// will result in// []string{"v1", "v2", "v3"}func ( *[]string, string, []string, string) {CommandLine.VarP(newStringSliceValue(, ), , "", )}// StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.func ( *[]string, , string, []string, string) {CommandLine.VarP(newStringSliceValue(, ), , , )}// StringSlice defines a string flag with specified name, default value, and usage string.// The return value is the address of a []string variable that stores the value of the flag.// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.// For example:// --ss="v1,v2" --ss="v3"// will result in// []string{"v1", "v2", "v3"}func ( *FlagSet) ( string, []string, string) *[]string { := []string{} .StringSliceVarP(&, , "", , )return &}// StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.func ( *FlagSet) (, string, []string, string) *[]string { := []string{} .StringSliceVarP(&, , , , )return &}// StringSlice defines a string flag with specified name, default value, and usage string.// The return value is the address of a []string variable that stores the value of the flag.// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.// For example:// --ss="v1,v2" --ss="v3"// will result in// []string{"v1", "v2", "v3"}func ( string, []string, string) *[]string {returnCommandLine.StringSliceP(, "", , )}// StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.func (, string, []string, string) *[]string {returnCommandLine.StringSliceP(, , , )}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.