github.com/HashDataInc/packer@v1.3.2/helper/flag-kv/flag.go (about) 1 package kvflag 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // Flag is a flag.Value implementation for parsing user variables 9 // from the command-line in the format of '-var key=value'. 10 type Flag map[string]string 11 12 func (v *Flag) String() string { 13 return "" 14 } 15 16 func (v *Flag) Set(raw string) error { 17 idx := strings.Index(raw, "=") 18 if idx == -1 { 19 return fmt.Errorf("No '=' value in arg: %s", raw) 20 } 21 22 if *v == nil { 23 *v = make(map[string]string) 24 } 25 26 key, value := raw[0:idx], raw[idx+1:] 27 (*v)[key] = value 28 return nil 29 }