Split Meta back out of StateMeta

Removing the call to StateMeta.Env, so that it doesn't need an embedded
Meta field. Embed Meta and StateMeta separately in all State commands.
This commit is contained in:
James Bardin 2017-03-01 10:10:47 -05:00
parent 4dac986a91
commit 39a5ddd381
15 changed files with 95 additions and 147 deletions

View File

@ -90,7 +90,7 @@ func (c *EnvDeleteCommand) Run(args []string) int {
// Lock the state if we can // Lock the state if we can
lockInfo := state.NewLockInfo() lockInfo := state.NewLockInfo()
lockInfo.Operation = "env new" lockInfo.Operation = "env delete"
lockID, err := clistate.Lock(sMgr, lockInfo, c.Ui, c.Colorize()) lockID, err := clistate.Lock(sMgr, lockInfo, c.Ui, c.Colorize())
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf("Error locking state: %s", err)) c.Ui.Error(fmt.Sprintf("Error locking state: %s", err))

View File

@ -11,6 +11,7 @@ import (
// StateListCommand is a Command implementation that lists the resources // StateListCommand is a Command implementation that lists the resources
// within a state file. // within a state file.
type StateListCommand struct { type StateListCommand struct {
Meta
StateMeta StateMeta
} }

View File

@ -16,12 +16,10 @@ func TestStateList(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateListCommand{ c := &StateListCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -49,12 +47,10 @@ func TestStateList_backendState(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateListCommand{ c := &StateListCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{} args := []string{}
@ -77,12 +73,10 @@ func TestStateList_noState(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateListCommand{ c := &StateListCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{} args := []string{}

View File

@ -11,13 +11,12 @@ import (
) )
// StateMeta is the meta struct that should be embedded in state subcommands. // StateMeta is the meta struct that should be embedded in state subcommands.
type StateMeta struct { type StateMeta struct{}
Meta
}
// State returns the state for this meta. This is different then Meta.State // State returns the state for this meta. This gets the appropriate state from
// in the way that backups are done. This configures backups to be timestamped // the backend, but changes the way that backups are done. This configures
// rather than just the original state path plus a backup path. // backups to be timestamped rather than just the original state path plus a
// backup path.
func (c *StateMeta) State(m *Meta) (state.State, error) { func (c *StateMeta) State(m *Meta) (state.State, error) {
// Load the backend // Load the backend
b, err := m.Backend(nil) b, err := m.Backend(nil)
@ -25,7 +24,7 @@ func (c *StateMeta) State(m *Meta) (state.State, error) {
return nil, err return nil, err
} }
env := c.Env() env := m.Env()
// Get the state // Get the state
s, err := b.State(env) s, err := b.State(env)
if err != nil { if err != nil {

View File

@ -10,6 +10,7 @@ import (
// StateMvCommand is a Command implementation that shows a single resource. // StateMvCommand is a Command implementation that shows a single resource.
type StateMvCommand struct { type StateMvCommand struct {
Meta
StateMeta StateMeta
} }

View File

@ -46,12 +46,10 @@ func TestStateMv(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateMvCommand{ c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -115,12 +113,10 @@ func TestStateMv_backupExplicit(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateMvCommand{ c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -172,12 +168,10 @@ func TestStateMv_stateOutNew(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateMvCommand{ c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -246,12 +240,10 @@ func TestStateMv_stateOutExisting(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateMvCommand{ c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -289,12 +281,10 @@ func TestStateMv_noState(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateMvCommand{ c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{"from", "to"} args := []string{"from", "to"}
@ -352,12 +342,10 @@ func TestStateMv_stateOutNew_count(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateMvCommand{ c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -532,12 +520,10 @@ func TestStateMv_stateOutNew_largeCount(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateMvCommand{ c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -615,12 +601,10 @@ func TestStateMv_stateOutNew_nestedModule(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateMvCommand{ c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{

View File

@ -11,6 +11,7 @@ import (
// StatePullCommand is a Command implementation that shows a single resource. // StatePullCommand is a Command implementation that shows a single resource.
type StatePullCommand struct { type StatePullCommand struct {
Meta
StateMeta StateMeta
} }

View File

@ -20,12 +20,10 @@ func TestStatePull(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StatePullCommand{ c := &StatePullCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{} args := []string{}

View File

@ -11,6 +11,7 @@ import (
// StatePushCommand is a Command implementation that shows a single resource. // StatePushCommand is a Command implementation that shows a single resource.
type StatePushCommand struct { type StatePushCommand struct {
Meta
StateMeta StateMeta
} }

View File

@ -20,12 +20,10 @@ func TestStatePush_empty(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StatePushCommand{ c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{"replace.tfstate"} args := []string{"replace.tfstate"}
@ -51,12 +49,10 @@ func TestStatePush_replaceMatch(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StatePushCommand{ c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{"replace.tfstate"} args := []string{"replace.tfstate"}
@ -82,12 +78,10 @@ func TestStatePush_lineageMismatch(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StatePushCommand{ c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{"replace.tfstate"} args := []string{"replace.tfstate"}
@ -113,12 +107,10 @@ func TestStatePush_serialNewer(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StatePushCommand{ c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{"replace.tfstate"} args := []string{"replace.tfstate"}
@ -144,12 +136,10 @@ func TestStatePush_serialOlder(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StatePushCommand{ c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{"replace.tfstate"} args := []string{"replace.tfstate"}

View File

@ -9,6 +9,7 @@ import (
// StateRmCommand is a Command implementation that shows a single resource. // StateRmCommand is a Command implementation that shows a single resource.
type StateRmCommand struct { type StateRmCommand struct {
Meta
StateMeta StateMeta
} }

View File

@ -46,12 +46,10 @@ func TestStateRm(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateRmCommand{ c := &StateRmCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -114,12 +112,10 @@ func TestStateRm_backupExplicit(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateRmCommand{ c := &StateRmCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -150,12 +146,10 @@ func TestStateRm_noState(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateRmCommand{ c := &StateRmCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{} args := []string{}

View File

@ -12,6 +12,7 @@ import (
// StateShowCommand is a Command implementation that shows a single resource. // StateShowCommand is a Command implementation that shows a single resource.
type StateShowCommand struct { type StateShowCommand struct {
Meta
StateMeta StateMeta
} }

View File

@ -34,12 +34,10 @@ func TestStateShow(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateShowCommand{ c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -94,12 +92,10 @@ func TestStateShow_multi(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateShowCommand{ c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -118,12 +114,10 @@ func TestStateShow_noState(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateShowCommand{ c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{} args := []string{}
@ -140,12 +134,10 @@ func TestStateShow_emptyState(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateShowCommand{ c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{
@ -171,12 +163,10 @@ func TestStateShow_emptyStateWithModule(t *testing.T) {
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &StateShowCommand{ c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{ Meta: Meta{
ContextOpts: testCtxConfig(p), ContextOpts: testCtxConfig(p),
Ui: ui, Ui: ui,
}, },
},
} }
args := []string{ args := []string{

View File

@ -46,11 +46,6 @@ func init() {
"debug": struct{}{}, // includes all subcommands "debug": struct{}{}, // includes all subcommands
} }
// meta struct used in state commands
stateMeta := command.StateMeta{
Meta: meta,
}
Commands = map[string]cli.CommandFactory{ Commands = map[string]cli.CommandFactory{
"apply": func() (cli.Command, error) { "apply": func() (cli.Command, error) {
return &command.ApplyCommand{ return &command.ApplyCommand{
@ -221,44 +216,42 @@ func init() {
}, },
"state": func() (cli.Command, error) { "state": func() (cli.Command, error) {
return &command.StateCommand{ return &command.StateCommand{}, nil
StateMeta: stateMeta,
}, nil
}, },
"state list": func() (cli.Command, error) { "state list": func() (cli.Command, error) {
return &command.StateListCommand{ return &command.StateListCommand{
StateMeta: stateMeta, Meta: meta,
}, nil }, nil
}, },
"state rm": func() (cli.Command, error) { "state rm": func() (cli.Command, error) {
return &command.StateRmCommand{ return &command.StateRmCommand{
StateMeta: stateMeta, Meta: meta,
}, nil }, nil
}, },
"state mv": func() (cli.Command, error) { "state mv": func() (cli.Command, error) {
return &command.StateMvCommand{ return &command.StateMvCommand{
StateMeta: stateMeta, Meta: meta,
}, nil }, nil
}, },
"state pull": func() (cli.Command, error) { "state pull": func() (cli.Command, error) {
return &command.StatePullCommand{ return &command.StatePullCommand{
StateMeta: stateMeta, Meta: meta,
}, nil }, nil
}, },
"state push": func() (cli.Command, error) { "state push": func() (cli.Command, error) {
return &command.StatePushCommand{ return &command.StatePushCommand{
StateMeta: stateMeta, Meta: meta,
}, nil }, nil
}, },
"state show": func() (cli.Command, error) { "state show": func() (cli.Command, error) {
return &command.StateShowCommand{ return &command.StateShowCommand{
StateMeta: stateMeta, Meta: meta,
}, nil }, nil
}, },
} }