Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming terraform workspace new command to terraform workspace create #35790

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func initCommands(
}, nil
},

"env new": func() (cli.Command, error) {
return &command.WorkspaceNewCommand{
"env create": func() (cli.Command, error) {
return &command.WorkspaceCreateCommand{
Meta: meta,
LegacyName: true,
}, nil
Expand Down Expand Up @@ -340,8 +340,8 @@ func initCommands(
}, nil
},

"workspace new": func() (cli.Command, error) {
return &command.WorkspaceNewCommand{
"workspace create": func() (cli.Command, error) {
return &command.WorkspaceCreateCommand{
Meta: meta,
}, nil
},
Expand Down
4 changes: 2 additions & 2 deletions internal/command/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1881,12 +1881,12 @@ func TestApply_terraformEnvNonDefault(t *testing.T) {
// Create new env
{
ui := new(cli.MockUi)
newCmd := &WorkspaceNewCommand{
createCmd := &WorkspaceCreateCommand{
Meta: Meta{
Ui: ui,
},
}
if code := newCmd.Run([]string{"test"}); code != 0 {
if code := createCmd.Run([]string{"test"}); code != 0 {
t.Fatal("error creating workspace")
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/command/state_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ func TestStatePush_forceRemoteState(t *testing.T) {

// create a new workspace
ui = new(cli.MockUi)
newCmd := &WorkspaceNewCommand{
createCmd := &WorkspaceCreateCommand{
Meta: Meta{Ui: ui, View: view},
}
if code := newCmd.Run([]string{"test"}); code != 0 {
if code := createCmd.Run([]string{"test"}); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/command/workspace_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *WorkspaceCommand) Help() string {
helpText := `
Usage: terraform [global options] workspace

new, list, show, select and delete Terraform workspaces.
create, list, show, select and delete Terraform workspaces.

`
return strings.TrimSpace(helpText)
Expand Down Expand Up @@ -70,7 +70,7 @@ const (
envDoesNotExist = `
Workspace %q doesn't exist.

You can create this workspace with the "new" subcommand
You can create this workspace with the "create" subcommand
or include the "-or-create" flag with the "select" subcommand.`

envChanged = `[reset][green]Switched to workspace %q.`
Expand Down
30 changes: 15 additions & 15 deletions internal/command/workspace_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ func TestWorkspace_createAndChange(t *testing.T) {
os.MkdirAll(td, 0755)
defer testChdir(t, td)()

newCmd := &WorkspaceNewCommand{}
createCmd := &WorkspaceCreateCommand{}

current, _ := newCmd.Workspace()
current, _ := createCmd.Workspace()
if current != backend.DefaultStateName {
t.Fatal("current workspace should be 'default'")
}

args := []string{"test"}
ui := new(cli.MockUi)
view, _ := testView(t)
newCmd.Meta = Meta{Ui: ui, View: view}
if code := newCmd.Run(args); code != 0 {
createCmd.Meta = Meta{Ui: ui, View: view}
if code := createCmd.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
}

current, _ = newCmd.Workspace()
current, _ = createCmd.Workspace()
if current != "test" {
t.Fatalf("current workspace should be 'test', got %q", current)
}
Expand All @@ -55,7 +55,7 @@ func TestWorkspace_createAndChange(t *testing.T) {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
}

current, _ = newCmd.Workspace()
current, _ = createCmd.Workspace()
if current != backend.DefaultStateName {
t.Fatal("current workspace should be 'default'")
}
Expand Down Expand Up @@ -86,10 +86,10 @@ func TestWorkspace_createAndList(t *testing.T) {
for _, env := range envs {
ui := new(cli.MockUi)
view, _ := testView(t)
newCmd := &WorkspaceNewCommand{
createCmd := &WorkspaceCreateCommand{
Meta: Meta{Ui: ui, View: view},
}
if code := newCmd.Run([]string{env}); code != 0 {
if code := createCmd.Run([]string{env}); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
}
}
Expand Down Expand Up @@ -145,14 +145,14 @@ func TestWorkspace_createAndShow(t *testing.T) {
t.Fatalf("\nexpected: %q\nactual: %q", expected, actual)
}

newCmd := &WorkspaceNewCommand{}
createCmd := &WorkspaceCreateCommand{}

env := []string{"test_a"}

// create test_a workspace
ui = new(cli.MockUi)
newCmd.Meta = Meta{Ui: ui, View: view}
if code := newCmd.Run(env); code != 0 {
createCmd.Meta = Meta{Ui: ui, View: view}
if code := createCmd.Run(env); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
}

Expand Down Expand Up @@ -192,10 +192,10 @@ func TestWorkspace_createInvalid(t *testing.T) {
for _, env := range envs {
ui := new(cli.MockUi)
view, _ := testView(t)
newCmd := &WorkspaceNewCommand{
createCmd := &WorkspaceCreateCommand{
Meta: Meta{Ui: ui, View: view},
}
if code := newCmd.Run([]string{env}); code == 0 {
if code := createCmd.Run([]string{env}); code == 0 {
t.Fatalf("expected failure: \n%s", ui.OutputWriter)
}
}
Expand Down Expand Up @@ -261,10 +261,10 @@ func TestWorkspace_createWithState(t *testing.T) {

args := []string{"-state", "test.tfstate", workspace}
ui = new(cli.MockUi)
newCmd := &WorkspaceNewCommand{
createCmd := &WorkspaceCreateCommand{
Meta: Meta{Ui: ui, View: view},
}
if code := newCmd.Run(args); code != 0 {
if code := createCmd.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ import (
"github.com/posener/complete"
)

type WorkspaceNewCommand struct {
type WorkspaceCreateCommand struct {
Meta
LegacyName bool
}

func (c *WorkspaceNewCommand) Run(args []string) int {
func (c *WorkspaceCreateCommand) Run(args []string) int {
args = c.Meta.process(args)
envCommandShowWarning(c.Ui, c.LegacyName)

var stateLock bool
var stateLockTimeout time.Duration
var statePath string
cmdFlags := c.Meta.defaultFlagSet("workspace new")
cmdFlags := c.Meta.defaultFlagSet("workspace create")
cmdFlags.BoolVar(&stateLock, "lock", true, "lock state")
cmdFlags.DurationVar(&stateLockTimeout, "lock-timeout", 0, "lock timeout")
cmdFlags.StringVar(&statePath, "state", "", "terraform state file")
Expand Down Expand Up @@ -129,7 +129,7 @@ func (c *WorkspaceNewCommand) Run(args []string) int {

if stateLock {
stateLocker := clistate.NewLocker(c.stateLockTimeout, views.NewStateLocker(arguments.ViewHuman, c.View))
if diags := stateLocker.Lock(stateMgr, "workspace-new"); diags.HasErrors() {
if diags := stateLocker.Lock(stateMgr, "workspace-create"); diags.HasErrors() {
c.showDiagnostics(diags)
return 1
}
Expand Down Expand Up @@ -168,22 +168,22 @@ func (c *WorkspaceNewCommand) Run(args []string) int {
return 0
}

func (c *WorkspaceNewCommand) AutocompleteArgs() complete.Predictor {
func (c *WorkspaceCreateCommand) AutocompleteArgs() complete.Predictor {
return completePredictSequence{
complete.PredictAnything,
complete.PredictDirs(""),
}
}

func (c *WorkspaceNewCommand) AutocompleteFlags() complete.Flags {
func (c *WorkspaceCreateCommand) AutocompleteFlags() complete.Flags {
return complete.Flags{
"-state": complete.PredictFiles("*.tfstate"),
}
}

func (c *WorkspaceNewCommand) Help() string {
func (c *WorkspaceCreateCommand) Help() string {
helpText := `
Usage: terraform [global options] workspace new [OPTIONS] NAME
Usage: terraform [global options] workspace create [OPTIONS] NAME

Create a new Terraform workspace.

Expand All @@ -201,6 +201,6 @@ Options:
return strings.TrimSpace(helpText)
}

func (c *WorkspaceNewCommand) Synopsis() string {
func (c *WorkspaceCreateCommand) Synopsis() string {
return "Create a new workspace"
}