github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/common/command/flag_slice_value.go (about)

     1  package command
     2  
     3  import "strings"
     4  
     5  // AppendSliceValue implements the flag.Value interface and allows multiple
     6  // calls to the same variable to append a list.
     7  type AppendSliceValue []string
     8  
     9  func (s *AppendSliceValue) String() string {
    10  	return strings.Join(*s, ",")
    11  }
    12  
    13  func (s *AppendSliceValue) Set(value string) error {
    14  	if *s == nil {
    15  		*s = make([]string, 0, 1)
    16  	}
    17  
    18  	*s = append(*s, value)
    19  	return nil
    20  }
    21  
    22  // SliceValue implements the flag.Value interface and allows a list of
    23  // strings to be given on the command line and properly parsed into a slice
    24  // of strings internally.
    25  type SliceValue []string
    26  
    27  func (s *SliceValue) String() string {
    28  	return strings.Join(*s, ",")
    29  }
    30  
    31  func (s *SliceValue) Set(value string) error {
    32  	*s = strings.Split(value, ",")
    33  	return nil
    34  }