github.com/cmalfait/terraform@v0.11.12-beta1/helper/variables/flag.go (about) 1 package variables 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // Flag a flag.Value implementation for parsing user variables 9 // from the command-line in the format of '-var key=value', where value is 10 // a type intended for use as a Terraform variable. 11 type Flag map[string]interface{} 12 13 func (v *Flag) String() string { 14 return "" 15 } 16 17 func (v *Flag) Set(raw string) error { 18 idx := strings.Index(raw, "=") 19 if idx == -1 { 20 return fmt.Errorf("No '=' value in arg: %s", raw) 21 } 22 23 key, input := raw[0:idx], raw[idx+1:] 24 25 // Trim the whitespace on the key 26 key = strings.TrimSpace(key) 27 if key == "" { 28 return fmt.Errorf("No key to left '=' in arg: %s", raw) 29 } 30 31 value, err := ParseInput(input) 32 if err != nil { 33 return err 34 } 35 36 *v = Merge(*v, map[string]interface{}{key: value}) 37 return nil 38 }