github.com/echohead/hub@v2.2.1+incompatible/commands/flag.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 type stringSliceValue []string 9 10 func (s *stringSliceValue) Set(val string) error { 11 *s = append(*s, val) 12 return nil 13 } 14 15 func (s *stringSliceValue) String() string { 16 return fmt.Sprintf("%s", *s) 17 } 18 19 type mapValue map[string]string 20 21 func (m mapValue) Set(val string) error { 22 v := strings.SplitN(val, "=", 2) 23 if len(v) != 2 { 24 return fmt.Errorf("Flag should be in the format of <name>=<value>") 25 } 26 27 m[v[0]] = v[1] 28 29 return nil 30 } 31 32 func (m mapValue) String() string { 33 s := make([]string, 0) 34 for k, v := range m { 35 s = append(s, fmt.Sprintf("%s=%s", k, v)) 36 } 37 38 return strings.Join(s, ",") 39 }