package pflag

import (
	
	
	
)

// -- boolSlice Value
type boolSliceValue struct {
	value   *[]bool
	changed bool
}

func newBoolSliceValue( []bool,  *[]bool) *boolSliceValue {
	 := new(boolSliceValue)
	.value = 
	*.value = 
	return 
}

// Set converts, and assigns, the comma-separated boolean argument string representation as the []bool value of this flag.
// If Set is called on a flag that already has a []bool assigned, the newly converted values will be appended.
func ( *boolSliceValue) ( string) error {

	// remove all quote characters
	 := strings.NewReplacer(`"`, "", `'`, "", "`", "")

	// read flag arguments with CSV parser
	,  := readAsCSV(.Replace())
	if  != nil &&  != io.EOF {
		return 
	}

	// parse boolean values into slice
	 := make([]bool, 0, len())
	for ,  := range  {
		,  := strconv.ParseBool(strings.TrimSpace())
		if  != nil {
			return 
		}
		 = append(, )
	}

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

	.changed = true

	return nil
}

// Type returns a string that uniquely represents this flag's type.
func ( *boolSliceValue) () string {
	return "boolSlice"
}

// String defines a "native" format for this boolean slice flag value.
func ( *boolSliceValue) () string {

	 := make([]string, len(*.value))
	for ,  := range *.value {
		[] = strconv.FormatBool()
	}

	,  := writeAsCSV()

	return "[" +  + "]"
}

func ( *boolSliceValue) ( string) (bool, error) {
	return strconv.ParseBool()
}

func ( *boolSliceValue) ( bool) string {
	return strconv.FormatBool()
}

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

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

func ( *boolSliceValue) () []string {
	 := make([]string, len(*.value))
	for ,  := range *.value {
		[] = .toString()
	}
	return 
}

func boolSliceConv( string) (interface{}, error) {
	 = strings.Trim(, "[]")
	// Empty string would cause a slice with one (empty) entry
	if len() == 0 {
		return []bool{}, nil
	}
	 := strings.Split(, ",")
	 := make([]bool, len())
	for ,  := range  {
		var  error
		[],  = strconv.ParseBool()
		if  != nil {
			return nil, 
		}
	}
	return , nil
}

// GetBoolSlice returns the []bool value of a flag with the given name.
func ( *FlagSet) ( string) ([]bool, error) {
	,  := .getFlagType(, "boolSlice", boolSliceConv)
	if  != nil {
		return []bool{}, 
	}
	return .([]bool), nil
}

// BoolSliceVar defines a boolSlice flag with specified name, default value, and usage string.
// The argument p points to a []bool variable in which to store the value of the flag.
func ( *FlagSet) ( *[]bool,  string,  []bool,  string) {
	.VarP(newBoolSliceValue(, ), , "", )
}

// BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
func ( *FlagSet) ( *[]bool, ,  string,  []bool,  string) {
	.VarP(newBoolSliceValue(, ), , , )
}

// BoolSliceVar defines a []bool flag with specified name, default value, and usage string.
// The argument p points to a []bool variable in which to store the value of the flag.
func ( *[]bool,  string,  []bool,  string) {
	CommandLine.VarP(newBoolSliceValue(, ), , "", )
}

// BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
func ( *[]bool, ,  string,  []bool,  string) {
	CommandLine.VarP(newBoolSliceValue(, ), , , )
}

// BoolSlice defines a []bool flag with specified name, default value, and usage string.
// The return value is the address of a []bool variable that stores the value of the flag.
func ( *FlagSet) ( string,  []bool,  string) *[]bool {
	 := []bool{}
	.BoolSliceVarP(&, , "", , )
	return &
}

// BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.
func ( *FlagSet) (,  string,  []bool,  string) *[]bool {
	 := []bool{}
	.BoolSliceVarP(&, , , , )
	return &
}

// BoolSlice defines a []bool flag with specified name, default value, and usage string.
// The return value is the address of a []bool variable that stores the value of the flag.
func ( string,  []bool,  string) *[]bool {
	return CommandLine.BoolSliceP(, "", , )
}

// BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.
func (,  string,  []bool,  string) *[]bool {
	return CommandLine.BoolSliceP(, , , )
}