enter "n" to cancel setup

pull/10616/head
Kelvin Wang 2018-10-11 20:49:00 -04:00
parent 91792ddf38
commit b5e7b5f138
1 changed files with 26 additions and 22 deletions

View File

@ -66,8 +66,6 @@ func getOnboardingRequest() (or *platform.OnboardingRequest) {
Writer: os.Stdout,
Reader: os.Stdin,
}
var confirmed bool
for !confirmed {
or = new(platform.OnboardingRequest)
fmt.Println(promptWithColor(`Welcome to InfluxDB 2.0!`, colorYellow))
or.User = getInput(ui, "Please type your primary username", "")
@ -75,7 +73,9 @@ func getOnboardingRequest() (or *platform.OnboardingRequest) {
or.Org = getInput(ui, "Please type your primary organization name.\r\nOr ENTER to use \"default\"", "default")
or.Bucket = getInput(ui, "Please type your primary bucket name.\r\nOr ENTER to use \"default\"", "default")
confirmed = getConfirm(ui, or)
if confirmed := getConfirm(ui, or); !confirmed {
fmt.Println("Setup is canceled.")
os.Exit(1)
}
return or
@ -100,13 +100,14 @@ func promptWithColor(s string, color []byte) string {
}
func getConfirm(ui *input.UI, or *platform.OnboardingRequest) bool {
prompt := promptWithColor("Confirm? (y/n)", colorRed)
for {
fmt.Print(promptWithColor(fmt.Sprintf(`
You have entered:
Username: %s
Organization: %s
Bucket: %s
`, or.User, or.Org, or.Bucket), colorCyan))
prompt := promptWithColor("Confirm? (y/n)", colorRed)
result, err := ui.Ask(prompt, &input.Options{
HideOrder: true,
})
@ -116,8 +117,11 @@ You have entered:
switch result {
case "y":
return true
default:
case "n":
return false
default:
continue
}
}
}