Merge pull request #1068 from influxdata/fix/exit_onboarding_n

enter "n" to cancel setup
pull/10616/head
kelwang 2018-10-11 21:26:28 -04:00 committed by GitHub
commit 2b9304d0ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 22 deletions

View File

@ -66,16 +66,16 @@ func getOnboardingRequest() (or *platform.OnboardingRequest) {
Writer: os.Stdout, Writer: os.Stdout,
Reader: os.Stdin, Reader: os.Stdin,
} }
var confirmed bool or = new(platform.OnboardingRequest)
for !confirmed { fmt.Println(promptWithColor(`Welcome to InfluxDB 2.0!`, colorYellow))
or = new(platform.OnboardingRequest) or.User = getInput(ui, "Please type your primary username", "")
fmt.Println(promptWithColor(`Welcome to InfluxDB 2.0!`, colorYellow)) or.Password = getPassword(ui)
or.User = getInput(ui, "Please type your primary username", "") or.Org = getInput(ui, "Please type your primary organization name.\r\nOr ENTER to use \"default\"", "default")
or.Password = getPassword(ui) or.Bucket = getInput(ui, "Please type your primary bucket name.\r\nOr ENTER to use \"default\"", "default")
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 return or
@ -100,24 +100,28 @@ func promptWithColor(s string, color []byte) string {
} }
func getConfirm(ui *input.UI, or *platform.OnboardingRequest) bool { func getConfirm(ui *input.UI, or *platform.OnboardingRequest) bool {
fmt.Print(promptWithColor(fmt.Sprintf(` prompt := promptWithColor("Confirm? (y/n)", colorRed)
for {
fmt.Print(promptWithColor(fmt.Sprintf(`
You have entered: You have entered:
Username: %s Username: %s
Organization: %s Organization: %s
Bucket: %s Bucket: %s
`, or.User, or.Org, or.Bucket), colorCyan)) `, or.User, or.Org, or.Bucket), colorCyan))
prompt := promptWithColor("Confirm? (y/n)", colorRed) result, err := ui.Ask(prompt, &input.Options{
result, err := ui.Ask(prompt, &input.Options{ HideOrder: true,
HideOrder: true, })
}) if err != nil {
if err != nil { os.Exit(1)
os.Exit(1) }
} switch result {
switch result { case "y":
case "y": return true
return true case "n":
default: return false
return false default:
continue
}
} }
} }