select: -or-create helptext and conditional output

This commit is contained in:
Brittan DeYoung 2022-08-31 13:28:28 -04:00
parent 5932540be3
commit 7d0d352eed

View File

@ -97,6 +97,8 @@ func (c *WorkspaceSelectCommand) Run(args []string) int {
}
}
var newState bool
if !found {
if orCreate {
_, err = b.StateMgr(name)
@ -104,6 +106,7 @@ func (c *WorkspaceSelectCommand) Run(args []string) int {
c.Ui.Error(err.Error())
return 1
}
newState = true
} else {
c.Ui.Error(fmt.Sprintf(envDoesNotExist, name))
return 1
@ -116,11 +119,16 @@ func (c *WorkspaceSelectCommand) Run(args []string) int {
return 1
}
if newState {
c.Ui.Output(c.Colorize().Color(fmt.Sprintf(
strings.TrimSpace(envCreated), name)))
} else {
c.Ui.Output(
c.Colorize().Color(
fmt.Sprintf(envChanged, name),
),
)
}
return 0
}
@ -142,6 +150,10 @@ Usage: terraform [global options] workspace select NAME
Select a different Terraform workspace.
Options:
-or-create=false Create the terraform workspace if if it doesnt exist.
`
return strings.TrimSpace(helpText)
}