Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: users can use "y" or "n" when confirming #1324

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions pkg/bootstrap/confirm/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ import (
"regexp"
"strings"

"github.com/mitchellh/mapstructure"
"github.com/modood/table"
"github.com/pkg/errors"
versionutil "k8s.io/apimachinery/pkg/util/version"

"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/core/action"
"github.com/kubesphere/kubekey/pkg/core/connector"
"github.com/kubesphere/kubekey/pkg/core/logger"
"github.com/kubesphere/kubekey/pkg/core/util"
"github.com/mitchellh/mapstructure"
"github.com/modood/table"
"github.com/pkg/errors"
versionutil "k8s.io/apimachinery/pkg/util/version"
)

// PreCheckResults defines the items to be checked.
Expand Down Expand Up @@ -131,10 +132,10 @@ func (i *InstallationConfirm) Execute(runtime connector.Runtime) error {
}
input = strings.TrimSpace(strings.ToLower(input))

switch input {
case "yes":
switch strings.ToLower(input) {
case "yes", "y":
confirmOK = true
case "no":
case "no", "n":
os.Exit(0)
default:
continue
Expand All @@ -151,24 +152,25 @@ type DeleteConfirm struct {
func (d *DeleteConfirm) Execute(runtime connector.Runtime) error {
reader := bufio.NewReader(os.Stdin)

var res string
for {
confirmOK := false
for !confirmOK {
fmt.Printf("Are you sure to delete this %s? [yes/no]: ", d.Content)
input, err := reader.ReadString('\n')
if err != nil {
return err
}
input = strings.TrimSpace(input)
input = strings.ToLower(strings.TrimSpace(input))

if input != "" && (input == "yes" || input == "no") {
res = input
break
switch strings.ToLower(input) {
case "yes", "y":
confirmOK = true
case "no", "n":
os.Exit(0)
default:
continue
}
}

if res == "no" {
os.Exit(0)
}
return nil
}

Expand Down Expand Up @@ -271,12 +273,12 @@ Warning:
if err != nil {
return err
}
input = strings.TrimSpace(input)
input = strings.ToLower(strings.TrimSpace(input))

switch input {
case "yes":
case "yes", "y":
confirmOK = true
case "no":
case "no", "n":
os.Exit(0)
default:
continue
Expand Down Expand Up @@ -320,13 +322,13 @@ func (c *CheckFile) Execute(runtime connector.Runtime) error {
}
fmt.Printf("%s already exists. Are you sure you want to overwrite this file? [yes/no]: ", c.FileName)
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(input)
input = strings.ToLower(strings.TrimSpace(input))

if input != "" {
switch input {
case "yes":
case "yes", "y":
stop = true
case "no":
case "no", "n":
os.Exit(0)
}
}
Expand Down