command: color changes, trimming newlines

This commit is contained in:
Mitchell Hashimoto 2017-03-01 12:59:40 -08:00
parent 4f680aa5b8
commit 1f614bd4d6
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 26 additions and 17 deletions

View File

@ -22,7 +22,7 @@ func (c *EnvCommand) Help() string {
helpText := `
Usage: terraform env
Create, change and delete Terraform environments.
Create, change and delete Terraform environments.
Subcommands:
@ -44,29 +44,41 @@ const (
envExists = `Environment %q already exists`
envDoesNotExist = `Environment %q doesn't exist!
envDoesNotExist = `
Environment %q doesn't exist!
You can create this environment with the "-new" option.`
envChanged = `[reset][green]Switched to environment %q!`
envCreated = `[reset][green]Created environment %q!`
envCreated = `
[reset][green][bold]Created and switched to environment %q![reset][green]
You're now on a new, empty environment. Environments isolate their state,
so if you run "terraform plan" Terraform will not see any existing state
for this configuration.
`
envDeleted = `[reset][green]Deleted environment %q!`
envNotEmpty = `Environment %[1]q is not empty!
Deleting %[1]q can result in dangling resources: resources that
envNotEmpty = `
Environment %[1]q is not empty!
Deleting %[1]q can result in dangling resources: resources that
exist but are no longer manageable by Terraform. Please destroy
these resources first. If you want to delete this environment
anyways and risk dangling resources, use the '-force' flag.
`
envWarnNotEmpty = `[reset][yellow]WARNING: %q was non-empty.
envWarnNotEmpty = `[reset][yellow]WARNING: %q was non-empty.
The resources managed by the deleted environment may still exist,
but are no longer manageable by Terraform since the state has
been deleted.
`
envDelCurrent = `Environment %[1]q is your active environment!
envDelCurrent = `
Environment %[1]q is your active environment!
You cannot delete the currently active environment. Please switch
to another environment and try again.
`

View File

@ -60,12 +60,12 @@ func (c *EnvDeleteCommand) Run(args []string) int {
}
if !exists {
c.Ui.Error(fmt.Sprintf(envDoesNotExist, delEnv))
c.Ui.Error(fmt.Sprintf(strings.TrimSpace(envDoesNotExist), delEnv))
return 1
}
if delEnv == c.Env() {
c.Ui.Error(fmt.Sprintf(envDelCurrent, delEnv))
c.Ui.Error(fmt.Sprintf(strings.TrimSpace(envDelCurrent), delEnv))
return 1
}
@ -84,7 +84,7 @@ func (c *EnvDeleteCommand) Run(args []string) int {
hasResources := sMgr.State().HasResources()
if hasResources && !force {
c.Ui.Error(fmt.Sprintf(envNotEmpty, delEnv))
c.Ui.Error(fmt.Sprintf(strings.TrimSpace(envNotEmpty), delEnv))
return 1
}

View File

@ -29,7 +29,7 @@ func (c *EnvNewCommand) Run(args []string) int {
}
args = cmdFlags.Args()
if len(args) == 0 {
c.Ui.Error("expected NAME.\n")
c.Ui.Error("Expected a single argument: NAME.\n")
return cli.RunResultHelp
}
@ -68,11 +68,8 @@ func (c *EnvNewCommand) Run(args []string) int {
return 1
}
c.Ui.Output(
c.Colorize().Color(
fmt.Sprintf(envCreated, newEnv),
),
)
c.Ui.Output(c.Colorize().Color(fmt.Sprintf(
strings.TrimSpace(envCreated), newEnv)))
if statePath == "" {
// if we're not loading a state, then we're done

View File

@ -21,7 +21,7 @@ func (c *EnvSelectCommand) Run(args []string) int {
}
args = cmdFlags.Args()
if len(args) == 0 {
c.Ui.Error("expected NAME.\n")
c.Ui.Error("Expected a single argument: NAME.\n")
return cli.RunResultHelp
}