command: FlagVar => FlagKV
This commit is contained in:
parent
4f91b98a3e
commit
3550f7ac3a
|
@ -9,15 +9,15 @@ import (
|
|||
"github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
// FlagVar is a flag.Value implementation for parsing user variables
|
||||
// FlagKV is a flag.Value implementation for parsing user variables
|
||||
// from the command-line in the format of '-var key=value'.
|
||||
type FlagVar map[string]string
|
||||
type FlagKV map[string]string
|
||||
|
||||
func (v *FlagVar) String() string {
|
||||
func (v *FlagKV) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (v *FlagVar) Set(raw string) error {
|
||||
func (v *FlagKV) Set(raw string) error {
|
||||
idx := strings.Index(raw, "=")
|
||||
if idx == -1 {
|
||||
return fmt.Errorf("No '=' value in arg: %s", raw)
|
||||
|
@ -32,16 +32,16 @@ func (v *FlagVar) Set(raw string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// FlagVarFile is a flag.Value implementation for parsing user variables
|
||||
// FlagKVFile is a flag.Value implementation for parsing user variables
|
||||
// from the command line in the form of files. i.e. '-var-file=foo'
|
||||
type FlagVarFile map[string]string
|
||||
type FlagKVFile map[string]string
|
||||
|
||||
func (v *FlagVarFile) String() string {
|
||||
func (v *FlagKVFile) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (v *FlagVarFile) Set(raw string) error {
|
||||
vs, err := loadVarFile(raw)
|
||||
func (v *FlagKVFile) Set(raw string) error {
|
||||
vs, err := loadKVFile(raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func (v *FlagVarFile) Set(raw string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadVarFile(rawPath string) (map[string]string, error) {
|
||||
func loadKVFile(rawPath string) (map[string]string, error) {
|
||||
path, err := homedir.Expand(rawPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
|
@ -7,11 +7,11 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestFlagVar_impl(t *testing.T) {
|
||||
var _ flag.Value = new(FlagVar)
|
||||
func TestFlagKV_impl(t *testing.T) {
|
||||
var _ flag.Value = new(FlagKV)
|
||||
}
|
||||
|
||||
func TestFlagVar(t *testing.T) {
|
||||
func TestFlagKV(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input string
|
||||
Output map[string]string
|
||||
|
@ -43,7 +43,7 @@ func TestFlagVar(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
f := new(FlagVar)
|
||||
f := new(FlagKV)
|
||||
err := f.Set(tc.Input)
|
||||
if (err != nil) != tc.Error {
|
||||
t.Fatalf("bad error. Input: %#v", tc.Input)
|
||||
|
@ -56,11 +56,11 @@ func TestFlagVar(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFlagVarFile_impl(t *testing.T) {
|
||||
var _ flag.Value = new(FlagVarFile)
|
||||
func TestFlagKVFile_impl(t *testing.T) {
|
||||
var _ flag.Value = new(FlagKVFile)
|
||||
}
|
||||
|
||||
func TestFlagVarFile(t *testing.T) {
|
||||
func TestFlagKVFile(t *testing.T) {
|
||||
inputLibucl := `
|
||||
foo = "bar"
|
||||
`
|
||||
|
@ -93,7 +93,7 @@ foo = "bar"
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
f := new(FlagVarFile)
|
||||
f := new(FlagKVFile)
|
||||
err := f.Set(path)
|
||||
if (err != nil) != tc.Error {
|
||||
t.Fatalf("bad error. Input: %#v", tc.Input)
|
|
@ -174,14 +174,16 @@ func (m *Meta) State() (state.State, error) {
|
|||
return m.state, nil
|
||||
}
|
||||
|
||||
path := m.statePath
|
||||
if path == "" {
|
||||
path = DefaultStateFilename
|
||||
localPath := m.statePath
|
||||
if localPath == "" {
|
||||
localPath = DefaultStateFilename
|
||||
}
|
||||
remotePath := filepath.Join(DefaultDataDir, DefaultStateFilename)
|
||||
|
||||
state, statePath, err := State(&StateOpts{
|
||||
LocalPath: path,
|
||||
LocalPath: localPath,
|
||||
LocalPathOut: m.stateOutPath,
|
||||
RemotePath: remotePath,
|
||||
BackupPath: m.backupPath,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -246,11 +248,11 @@ func (m *Meta) contextOpts() *terraform.ContextOpts {
|
|||
func (m *Meta) flagSet(n string) *flag.FlagSet {
|
||||
f := flag.NewFlagSet(n, flag.ContinueOnError)
|
||||
f.BoolVar(&m.input, "input", true, "input")
|
||||
f.Var((*FlagVar)(&m.variables), "var", "variables")
|
||||
f.Var((*FlagVarFile)(&m.variables), "var-file", "variable file")
|
||||
f.Var((*FlagKV)(&m.variables), "var", "variables")
|
||||
f.Var((*FlagKVFile)(&m.variables), "var-file", "variable file")
|
||||
|
||||
if m.autoKey != "" {
|
||||
f.Var((*FlagVarFile)(&m.autoVariables), m.autoKey, "variable file")
|
||||
f.Var((*FlagKVFile)(&m.autoVariables), m.autoKey, "variable file")
|
||||
}
|
||||
|
||||
// Create an io.Writer that writes to our Ui properly for errors.
|
||||
|
|
|
@ -20,6 +20,9 @@ type StateOpts struct {
|
|||
LocalPath string
|
||||
LocalPathOut string
|
||||
|
||||
// RemotePath is the path where the remote state cache would be.
|
||||
RemotePath string
|
||||
|
||||
// BackupPath is the path where the backup will be placed. If not set,
|
||||
// it is assumed to be the path where the state is stored locally
|
||||
// plus the DefaultBackupExtension.
|
||||
|
@ -37,14 +40,15 @@ func State(opts *StateOpts) (state.State, string, error) {
|
|||
var resultPath string
|
||||
|
||||
// Get the remote state cache path
|
||||
remoteCachePath := filepath.Join(DefaultDataDir, DefaultStateFilename)
|
||||
if _, err := os.Stat(remoteCachePath); err == nil {
|
||||
// We have a remote state, initialize that.
|
||||
result, err = remoteStateFromPath(remoteCachePath)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
if opts.RemotePath != "" {
|
||||
if _, err := os.Stat(opts.RemotePath); err == nil {
|
||||
// We have a remote state, initialize that.
|
||||
result, err = remoteStateFromPath(opts.RemotePath)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
resultPath = opts.RemotePath
|
||||
}
|
||||
resultPath = remoteCachePath
|
||||
}
|
||||
|
||||
// Do we have a local state?
|
||||
|
|
Loading…
Reference in New Issue