command/0.13upgrade: make confirmation more user-friendly (#25142)

I feel the current confirmation prompt for 0.13upgrade command is
ambiguous what is expected. Actually, when I used it for the first time,
I cancelled it by typing `y` instead of `yes`.

I believe it would be great if the 0.13upgrade command tell us the
expected value for confirmation like 0.12upgrade.
This commit is contained in:
Masayuki Morita 2020-06-09 02:36:19 +09:00 committed by GitHub
parent f2beafd348
commit ee913a1c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package command
import (
"context"
"fmt"
"io/ioutil"
"os"
@ -14,6 +15,7 @@ import (
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/internal/getproviders"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform/tfdiags"
tfversion "github.com/hashicorp/terraform/version"
"github.com/zclconf/go-cty/cty"
@ -148,7 +150,11 @@ command and dealing with them before running this command again.
if dir != "." {
query = fmt.Sprintf("Would you like to upgrade the module in %s?", dir)
}
v, err := c.Ui.Ask(query)
v, err := c.UIInput().Input(context.Background(), &terraform.InputOpts{
Id: "approve",
Query: query,
Description: `Only 'yes' will be accepted to confirm.`,
})
if err != nil {
diags = diags.Append(err)
c.showDiagnostics(diags)

View File

@ -1,7 +1,6 @@
package command
import (
"bytes"
"io/ioutil"
"os"
"path"
@ -215,10 +214,10 @@ func TestZeroThirteenUpgrade_confirm(t *testing.T) {
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"yes"})()
ui := new(cli.MockUi)
inputBuf := &bytes.Buffer{}
ui.InputReader = inputBuf
inputBuf.WriteString("yes")
c := &ZeroThirteenUpgradeCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
@ -244,10 +243,10 @@ func TestZeroThirteenUpgrade_cancel(t *testing.T) {
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"no"})()
ui := new(cli.MockUi)
inputBuf := &bytes.Buffer{}
ui.InputReader = inputBuf
inputBuf.WriteString("no")
c := &ZeroThirteenUpgradeCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),