package pflag

import (
	
	
	
	
)

// -- ipSlice Value
type 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 {
		return 
	}

	// parse ip values into slice
	 := make([]net.IP, 0, len())
	for ,  := range  {
		 := net.ParseIP(strings.TrimSpace())
		if  == nil {
			return fmt.Errorf("invalid string being converted to IP address: %s", )
		}
		 = append(, )
	}

	if !.changed {
		*.value = 
	} else {
		*.value = append(*.value, ...)
	}

	.changed = true

	return nil
}

// 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) {
	return net.ParseIP(strings.TrimSpace()), nil
}

func ( *ipSliceValue) ( net.IP) string {
	return .String()
}

func ( *ipSliceValue) ( string) error {
	,  := .fromString()
	if  != nil {
		return 
	}
	*.value = append(*.value, )
	return nil
}

func ( *ipSliceValue) ( []string) error {
	 := make([]net.IP, len())
	for ,  := range  {
		var  error
		[],  = .fromString()
		if  != nil {
			return 
		}
	}
	*.value = 
	return nil
}

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) entry
	if len() == 0 {
		return []net.IP{}, nil
	}
	 := strings.Split(, ",")
	 := make([]net.IP, len())
	for ,  := range  {
		 := net.ParseIP(strings.TrimSpace())
		if  == nil {
			return nil, fmt.Errorf("invalid string being converted to IP address: %s", )
		}
		[] = 
	}
	return , nil
}

// GetIPSlice returns the []net.IP value of a flag with the given name
func ( *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 {
	return CommandLine.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 {
	return CommandLine.IPSliceP(, , , )
}