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