vendor/github.com/spf13/pflag/bool_slice.go
changeset 251 1c52a0eeb952
parent 242 2a9ec03fe5a1
equal deleted inserted replaced
250:c040f992052f 251:1c52a0eeb952
    67 	}
    67 	}
    68 
    68 
    69 	out, _ := writeAsCSV(boolStrSlice)
    69 	out, _ := writeAsCSV(boolStrSlice)
    70 
    70 
    71 	return "[" + out + "]"
    71 	return "[" + out + "]"
       
    72 }
       
    73 
       
    74 func (s *boolSliceValue) fromString(val string) (bool, error) {
       
    75 	return strconv.ParseBool(val)
       
    76 }
       
    77 
       
    78 func (s *boolSliceValue) toString(val bool) string {
       
    79 	return strconv.FormatBool(val)
       
    80 }
       
    81 
       
    82 func (s *boolSliceValue) Append(val string) error {
       
    83 	i, err := s.fromString(val)
       
    84 	if err != nil {
       
    85 		return err
       
    86 	}
       
    87 	*s.value = append(*s.value, i)
       
    88 	return nil
       
    89 }
       
    90 
       
    91 func (s *boolSliceValue) Replace(val []string) error {
       
    92 	out := make([]bool, len(val))
       
    93 	for i, d := range val {
       
    94 		var err error
       
    95 		out[i], err = s.fromString(d)
       
    96 		if err != nil {
       
    97 			return err
       
    98 		}
       
    99 	}
       
   100 	*s.value = out
       
   101 	return nil
       
   102 }
       
   103 
       
   104 func (s *boolSliceValue) GetSlice() []string {
       
   105 	out := make([]string, len(*s.value))
       
   106 	for i, d := range *s.value {
       
   107 		out[i] = s.toString(d)
       
   108 	}
       
   109 	return out
    72 }
   110 }
    73 
   111 
    74 func boolSliceConv(val string) (interface{}, error) {
   112 func boolSliceConv(val string) (interface{}, error) {
    75 	val = strings.Trim(val, "[]")
   113 	val = strings.Trim(val, "[]")
    76 	// Empty string would cause a slice with one (empty) entry
   114 	// Empty string would cause a slice with one (empty) entry