Skip to content

Commit 7267df6

Browse files
author
Josh Berry
authored
Fix the "delete namespace" prompt (#406)
We were improperly lower-casing the user's input when asking them to confirm the namespace name, and then providing no feedback to the user if the name didn't match, leaving them with the false impression that the namespace was deleted even though we didn't even try. Closes #405
1 parent be7f5ed commit 7267df6

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

common/util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func AllowedEnumValues(names map[int32]string) []string {
489489
}
490490

491491
func PromptYes(msg string, autoConfirm bool) bool {
492-
return Prompt(msg, autoConfirm, "yes", "y")
492+
return Prompt(msg, autoConfirm, "yes", "y", "Yes", "YES", "Y")
493493
}
494494

495495
// Prompt user to confirm/deny action. Supports empty expectedInputs.
@@ -504,16 +504,16 @@ func Prompt(msg string, autoConfirm bool, expectedInputs ...string) bool {
504504
fmt.Print(text)
505505
} else {
506506
text, _ = reader.ReadString('\n')
507+
text = strings.TrimRight(text, "\n")
507508
}
508509
fmt.Println()
509510

510511
if len(expectedInputs) == 0 {
511512
return true
512513
}
513514

514-
textLower := strings.ToLower(strings.TrimSpace(text))
515515
for _, expectedInput := range expectedInputs {
516-
if expectedInput == textLower {
516+
if expectedInput == text {
517517
return true
518518
}
519519
}

namespace/namespace_commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func DeleteNamespace(c *cli.Context) error {
303303

304304
promptMsg := color.Red(c, "Are you sure you want to delete namespace %s? Type namespace name to confirm:", ns)
305305
if !common.Prompt(promptMsg, c.Bool(common.FlagYes), ns) {
306-
return nil
306+
return fmt.Errorf("namespace name does not match: expected %v", ns)
307307
}
308308

309309
client := cliclient.Factory(c.App).OperatorClient(c)

0 commit comments

Comments
 (0)