package pflagimport ()// -- ipSlice Valuetype ipSliceValue struct { value *[]net.IP changed bool}func newIPSliceValue( []net.IP, *[]net.IP) *ipSliceValue { := new(ipSliceValue) .value = *.value = return}// Set converts, and assigns, the comma-separated IP argument string representation as the []net.IP value of this flag.// If Set is called on a flag that already has a []net.IP assigned, the newly converted values will be appended.func ( *ipSliceValue) ( string) error {// remove all quote characters := strings.NewReplacer(`"`, "", `'`, "", "`", "")// read flag arguments with CSV parser , := readAsCSV(.Replace())if != nil && != io.EOF { //nolint:errorlint // not using errors.Is for compatibility with go1.12return }// parse ip values into slice := make([]net.IP, 0, len())for , := range { := net.ParseIP(strings.TrimSpace())if == nil {returnfmt.Errorf("invalid string being converted to IP address: %s", ) } = append(, ) }if !.changed { *.value = } else { *.value = append(*.value, ...) } .changed = truereturnnil}// Type returns a string that uniquely represents this flag's type.func ( *ipSliceValue) () string {return"ipSlice"}// String defines a "native" format for this net.IP slice flag value.func ( *ipSliceValue) () string { := make([]string, len(*.value))for , := range *.value { [] = .String() } , := writeAsCSV()return"[" + + "]"}func ( *ipSliceValue) ( string) (net.IP, error) { := net.ParseIP(strings.TrimSpace())if == nil {returnnil, fmt.Errorf("invalid string being converted to IP address: %s", ) }return , nil}func ( *ipSliceValue) ( net.IP) string {return .String()}func ( *ipSliceValue) ( string) error { , := .fromString()if != nil {return } *.value = append(*.value, )returnnil}func ( *ipSliceValue) ( []string) error { := make([]net.IP, len())for , := range { , := .fromString()if != nil {return } [] = } *.value = returnnil}func ( *ipSliceValue) () []string { := make([]string, len(*.value))for , := range *.value { [] = .toString() }return}func ipSliceConv( string) (interface{}, error) { = strings.Trim(, "[]")// Empty string would cause a slice with one (empty) entryiflen() == 0 {return []net.IP{}, nil } := strings.Split(, ",") := make([]net.IP, len())for , := range { := net.ParseIP(strings.TrimSpace())if == nil {returnnil, fmt.Errorf("invalid string being converted to IP address: %s", ) } [] = }return , nil}// GetIPSlice returns the []net.IP value of a flag with the given namefunc ( *FlagSet) ( string) ([]net.IP, error) { , := .getFlagType(, "ipSlice", ipSliceConv)if != nil {return []net.IP{}, }return .([]net.IP), nil}// IPSliceVar defines a ipSlice flag with specified name, default value, and usage string.// The argument p points to a []net.IP variable in which to store the value of the flag.func ( *FlagSet) ( *[]net.IP, string, []net.IP, string) { .VarP(newIPSliceValue(, ), , "", )}// IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.func ( *FlagSet) ( *[]net.IP, , string, []net.IP, string) { .VarP(newIPSliceValue(, ), , , )}// IPSliceVar defines a []net.IP flag with specified name, default value, and usage string.// The argument p points to a []net.IP variable in which to store the value of the flag.func ( *[]net.IP, string, []net.IP, string) {CommandLine.VarP(newIPSliceValue(, ), , "", )}// IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.func ( *[]net.IP, , string, []net.IP, string) {CommandLine.VarP(newIPSliceValue(, ), , , )}// IPSlice defines a []net.IP flag with specified name, default value, and usage string.// The return value is the address of a []net.IP variable that stores the value of that flag.func ( *FlagSet) ( string, []net.IP, string) *[]net.IP { := []net.IP{} .IPSliceVarP(&, , "", , )return &}// IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.func ( *FlagSet) (, string, []net.IP, string) *[]net.IP { := []net.IP{} .IPSliceVarP(&, , , , )return &}// IPSlice defines a []net.IP flag with specified name, default value, and usage string.// The return value is the address of a []net.IP variable that stores the value of the flag.func ( string, []net.IP, string) *[]net.IP {returnCommandLine.IPSliceP(, "", , )}// IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.func (, string, []net.IP, string) *[]net.IP {returnCommandLine.IPSliceP(, , , )}
The pages are generated with Goldsv0.8.7. (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.