@@ -16,10 +16,11 @@ limitations under the License.
1616package cmd
1717
1818import (
19- "bufio"
2019 "fmt"
2120 "os"
21+ "strings"
2222
23+ "github.com/c-bata/go-prompt"
2324 homedir "github.com/mitchellh/go-homedir"
2425 "github.com/spf13/cobra"
2526 "github.com/spf13/viper"
@@ -110,22 +111,22 @@ func dialogDesctructiveConfirmProceed() (proceed bool) {
110111 var haveConfirmationAnswer bool
111112 utils .PrintTeal ("Tip: Avoid future confirmations by passing --force\n \n " )
112113
113- for ! haveConfirmationAnswer {
114- utils .PrintRed ("This is a destructive operation. Continue (yes/[no])?: " )
115- scanner := bufio .NewScanner (os .Stdin )
116- scanner .Scan ()
117- answer := scanner .Text ()
118-
119- if answer != "" && answer != "yes" && answer != "no" {
120- utils .PrintYellow ("invalid input.\n " )
121- continue
114+ f := func (d prompt.Document ) []prompt.Suggest {
115+ s := []prompt.Suggest {
116+ {Text : "yes" , Description : "I understand continue" },
117+ {Text : "no" , Description : "I would like to cancel" },
122118 }
119+ return prompt .FilterHasPrefix (s , d .GetWordBeforeCursor (), true )
120+ }
123121
124- haveConfirmationAnswer = true
125- if answer == "no" || answer == "" {
126- proceed = false
127- } else if answer == "yes" {
128- proceed = true
122+ for ! haveConfirmationAnswer {
123+ fmt .Print ("This is a destructive operation. Continue? " )
124+ answer := strings .ToLower (prompt .Input ("> " , f , prompt .OptionShowCompletionAtStart ()))
125+ if answer == "yes" || answer == "no" {
126+ haveConfirmationAnswer = true
127+ if answer == "yes" {
128+ proceed = true
129+ }
129130 }
130131 }
131132
0 commit comments