Skip to content

Commit

Permalink
command: "terraform workspace show" to print current workspace name
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhelmick authored and apparentlymart committed Jun 27, 2017
1 parent da1c45b commit 8443b51
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
42 changes: 42 additions & 0 deletions command/env_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package command

import (
"fmt"
"strings"
)

type EnvShowCommand struct {
Meta
}

func (c *EnvShowCommand) Run(args []string) int {
args = c.Meta.process(args, true)

cmdFlags := c.Meta.flagSet("env show")
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
return 1
}

env := c.Env()
c.Ui.Output(
c.Colorize().Color(
fmt.Sprintf(env),
),
)

return 1
}

func (c *EnvShowCommand) Help() string {
helpText := `
Usage: terraform env show
Show current Terraform environment.
`
return strings.TrimSpace(helpText)
}

func (c *EnvShowCommand) Synopsis() string {
return "Show current Terraform environment"
}
1 change: 1 addition & 0 deletions command/workspace_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Usage: terraform workspace
Subcommands:
show Show the current workspace name.
list List workspaces.
select Select a workspace.
new Create a new workspace.
Expand Down
6 changes: 6 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ func init() {
}, nil
},

"env show": func() (cli.Command, error) {
return &command.EnvShowCommand{
Meta: meta,
}, nil
},

"env list": func() (cli.Command, error) {
return &command.WorkspaceListCommand{
Meta: meta,
Expand Down

0 comments on commit 8443b51

Please sign in to comment.