2016-12-10 20:10:25 +01:00
|
|
|
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 {
|
2016-12-10 20:44:17 +01:00
|
|
|
idx := strings.Index(raw, "=")
|
2016-12-10 20:10:25 +01:00
|
|
|
if idx == -1 {
|
2016-12-10 20:44:17 +01:00
|
|
|
return fmt.Errorf("No '=' value in arg: %s", raw)
|
2016-12-10 20:10:25 +01:00
|
|
|
}
|
|
|
|
|
2016-12-10 20:44:17 +01:00
|
|
|
key, input := raw[0:idx], raw[idx+1:]
|
|
|
|
value, err := ParseInput(input)
|
2016-12-10 20:10:25 +01:00
|
|
|
if err != nil {
|
2016-12-10 20:44:17 +01:00
|
|
|
return err
|
2016-12-10 20:10:25 +01:00
|
|
|
}
|
|
|
|
|
2016-12-10 20:44:17 +01:00
|
|
|
*v = Merge(*v, map[string]interface{}{key: value})
|
2016-12-10 20:10:25 +01:00
|
|
|
return nil
|
|
|
|
}
|