diff --git a/command/env_command.go b/command/env_command.go index d2f16e8e1..7701a2b78 100644 --- a/command/env_command.go +++ b/command/env_command.go @@ -1,12 +1,6 @@ package command -import ( - "fmt" - "strings" - - "github.com/hashicorp/terraform/backend" - "github.com/mitchellh/cli" -) +import "strings" // EnvCommand is a Command Implementation that manipulates local state // environments. @@ -19,34 +13,7 @@ func (c *EnvCommand) Run(args []string) int { cmdFlags := c.Meta.flagSet("env") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } - if err := cmdFlags.Parse(args); err != nil { - return 1 - } - args = cmdFlags.Args() - if len(args) > 0 { - c.Ui.Error("0 arguments expected.\n") - return cli.RunResultHelp - } - // Load the backend - b, err := c.Backend(nil) - if err != nil { - c.Ui.Error(fmt.Sprintf("Failed to load backend: %s", err)) - return 1 - } - - multi, ok := b.(backend.MultiState) - if !ok { - c.Ui.Error(envNotSupported) - return 1 - } - _, current, err := multi.States() - if err != nil { - c.Ui.Error(err.Error()) - return 1 - } - - c.Ui.Output(fmt.Sprintf("Current environment is %q\n", current)) c.Ui.Output(c.Help()) return 0 } diff --git a/command/env_delete.go b/command/env_delete.go index 5295e4db4..95b734d44 100644 --- a/command/env_delete.go +++ b/command/env_delete.go @@ -26,15 +26,21 @@ func (c *EnvDeleteCommand) Run(args []string) int { return 1 } args = cmdFlags.Args() - if len(args) != 1 { + if len(args) == 0 { c.Ui.Error("expected NAME.\n") return cli.RunResultHelp } delEnv := args[0] + configPath, err := ModulePath(args[1:]) + if err != nil { + c.Ui.Error(err.Error()) + return 1 + } + // Load the backend - b, err := c.Backend(nil) + b, err := c.Backend(&BackendOpts{ConfigPath: configPath}) if err != nil { c.Ui.Error(fmt.Sprintf("Failed to load backend: %s", err)) return 1 @@ -134,7 +140,7 @@ func (c *EnvDeleteCommand) Run(args []string) int { } func (c *EnvDeleteCommand) Help() string { helpText := ` -Usage: terraform env delete [OPTIONS] NAME +Usage: terraform env delete [OPTIONS] NAME [DIR] Delete a Terraform environment diff --git a/command/env_list.go b/command/env_list.go index 23761b99e..cffeb38f3 100644 --- a/command/env_list.go +++ b/command/env_list.go @@ -21,8 +21,14 @@ func (c *EnvListCommand) Run(args []string) int { return 1 } + configPath, err := ModulePath(args) + if err != nil { + c.Ui.Error(err.Error()) + return 1 + } + // Load the backend - b, err := c.Backend(nil) + b, err := c.Backend(&BackendOpts{ConfigPath: configPath}) if err != nil { c.Ui.Error(fmt.Sprintf("Failed to load backend: %s", err)) return 1 @@ -56,7 +62,7 @@ func (c *EnvListCommand) Run(args []string) int { func (c *EnvListCommand) Help() string { helpText := ` -Usage: terraform env list +Usage: terraform env list [DIR] List Terraform environments. ` diff --git a/command/env_new.go b/command/env_new.go index 026199eeb..eb5c99076 100644 --- a/command/env_new.go +++ b/command/env_new.go @@ -29,15 +29,21 @@ func (c *EnvNewCommand) Run(args []string) int { return 1 } args = cmdFlags.Args() - if len(args) != 1 { + if len(args) == 0 { c.Ui.Error("expected NAME.\n") return cli.RunResultHelp } newEnv := args[0] + configPath, err := ModulePath(args[1:]) + if err != nil { + c.Ui.Error(err.Error()) + return 1 + } + // Load the backend - b, err := c.Backend(nil) + b, err := c.Backend(&BackendOpts{ConfigPath: configPath}) if err != nil { c.Ui.Error(fmt.Sprintf("Failed to load backend: %s", err)) return 1 @@ -116,7 +122,7 @@ func (c *EnvNewCommand) Run(args []string) int { func (c *EnvNewCommand) Help() string { helpText := ` -Usage: terraform env new [OPTIONS] NAME +Usage: terraform env new [OPTIONS] NAME [DIR] Create a new Terraform environment. diff --git a/command/env_select.go b/command/env_select.go index 7598b4204..adfd2f056 100644 --- a/command/env_select.go +++ b/command/env_select.go @@ -21,13 +21,19 @@ func (c *EnvSelectCommand) Run(args []string) int { return 1 } args = cmdFlags.Args() - if len(args) != 1 { + if len(args) == 0 { c.Ui.Error("expected NAME.\n") return cli.RunResultHelp } + configPath, err := ModulePath(args[1:]) + if err != nil { + c.Ui.Error(err.Error()) + return 1 + } + // Load the backend - b, err := c.Backend(nil) + b, err := c.Backend(&BackendOpts{ConfigPath: configPath}) if err != nil { c.Ui.Error(fmt.Sprintf("Failed to load backend: %s", err)) return 1 @@ -81,7 +87,7 @@ func (c *EnvSelectCommand) Run(args []string) int { func (c *EnvSelectCommand) Help() string { helpText := ` -Usage: terraform env select NAME +Usage: terraform env select NAME [DIR] Change Terraform environment. `