Skip to content

Commit

Permalink
chore: add hostname for reset confirm. (#4890)
Browse files Browse the repository at this point in the history
* chore: add hostname for reset confirm.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* chore: add hostname for reset confirm.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

---------

Signed-off-by: yy <[email protected]>
  • Loading branch information
lingdie authored Sep 20, 2024
1 parent 74f8ba5 commit ff82fc3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ require (
go.etcd.io/etcd/client/v3 v3.5.7 // indirect
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9 // indirect
k8s.io/cloud-provider v0.0.0 // indirect
k8s.io/cloud-provider v0.27.4 // indirect
k8s.io/controller-manager v0.27.4 // indirect
k8s.io/cri-api v0.27.4 // indirect
k8s.io/kms v0.27.4 // indirect
Expand Down
13 changes: 6 additions & 7 deletions pkg/utils/confirm/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package confirm

import (
"errors"
"regexp"
"os"

"github.com/manifoldco/promptui"

Expand All @@ -25,14 +25,13 @@ import (

// Confirm is send the prompt and get result
func Confirm(prompt, cancel string) (bool, error) {
var yesRx = regexp.MustCompile("^(?:y(?:es)?)$")
var noRx = regexp.MustCompile("^(?:n(?:o)?)$")
promptLabel := "Yes [y/yes], No [n/no]"
var hostname, _ = os.Hostname()
promptLabel := "Do you want to continue on '" + hostname + "' cluster? Input '" + hostname + "' to continue"
logger.Info(prompt)

validate := func(input string) error {
if !yesRx.MatchString(input) && !noRx.MatchString(input) {
return errors.New("invalid input, please enter 'y', 'yes', 'n', or 'no'")
if input != hostname {
return errors.New("invalid input, please enter " + hostname + " to continue")
}
return nil
}
Expand All @@ -47,7 +46,7 @@ func Confirm(prompt, cancel string) (bool, error) {
return false, err
}

if yesRx.MatchString(result) {
if result == hostname {
return true, nil
}
logger.Warn(cancel)
Expand Down

0 comments on commit ff82fc3

Please sign in to comment.