Skip to content

Commit 80d5bd2

Browse files
CLOUDP-295778: [AtlasCLI] Fix prompt when deleting search node (#3551)
1 parent 23a66ee commit 80d5bd2

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

internal/cli/delete_opts.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ import (
2323
)
2424

2525
const (
26-
fallbackSuccessMessage = "'%s' deleted\n"
27-
fallbackFailMessage = "Entry not deleted"
26+
fallbackSuccessMessage = "'%s' deleted\n"
27+
fallbackFailMessage = "Entry not deleted"
28+
defaultConfirmationPrompt = "Are you sure you want to delete: %s"
2829
)
2930

3031
// DeleteOpts options required when deleting a resource.
3132
// A command can compose this struct and then safely rely on the methods Prompt, or Delete
3233
// to manage the interactions with the user.
3334
type DeleteOpts struct {
34-
Entry string
35-
Confirm bool
36-
successMsg string
37-
failMsg string
35+
Entry string
36+
Confirm bool
37+
confirmationPrompt string
38+
successMsg string
39+
failMsg string
3840
}
3941

4042
func NewDeleteOpts(successMsg, failMsg string) *DeleteOpts {
@@ -44,6 +46,14 @@ func NewDeleteOpts(successMsg, failMsg string) *DeleteOpts {
4446
}
4547
}
4648

49+
func NewDeleteOptsWithPrompt(successMsg, failMsg, confirmationPrompt string) *DeleteOpts {
50+
return &DeleteOpts{
51+
successMsg: successMsg,
52+
failMsg: failMsg,
53+
confirmationPrompt: confirmationPrompt,
54+
}
55+
}
56+
4757
// Delete deletes a resource not associated to a project, it expects a callback
4858
// that should perform the deletion from the store.
4959
func (opts *DeleteOpts) Delete(d any, a ...string) error {
@@ -86,7 +96,13 @@ func (opts *DeleteOpts) Prompt() error {
8696
return nil
8797
}
8898

89-
p := prompt.NewDeleteConfirm(opts.Entry)
99+
var template = opts.confirmationPrompt
100+
if template == "" {
101+
template = defaultConfirmationPrompt
102+
}
103+
104+
message := fmt.Sprintf(template, opts.Entry)
105+
p := prompt.NewConfirm(message)
90106
return telemetry.TrackAskOne(p, &opts.Confirm)
91107
}
92108

internal/cli/maintenance/clear.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (opts *ClearOpts) Prompt() error {
6464
return nil
6565
}
6666

67-
p := prompt.NewDeleteConfirm("maintenance window")
67+
p := prompt.NewConfirm("Are you sure you want to delete: maintenance window")
6868
return telemetry.TrackAskOne(p, &opts.Confirm)
6969
}
7070

internal/cli/search/nodes/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (opts *DeleteOpts) watcher() (any, bool, error) {
8585
// atlas clusters search nodes delete [--clusterName clusterName].
8686
func DeleteBuilder() *cobra.Command {
8787
opts := &DeleteOpts{
88-
DeleteOpts: cli.NewDeleteOpts(deleteTemplate, "Search node not deleted."),
88+
DeleteOpts: cli.NewDeleteOptsWithPrompt(deleteTemplate, "Search node not deleted.", "Are you sure you want to delete search nodes for cluster: %s"),
8989
}
9090

9191
cmd := &cobra.Command{

internal/prompt/prompt.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ import (
1818
"github.com/AlecAivazis/survey/v2"
1919
)
2020

21-
// NewDeleteConfirm creates a prompt to confirm if the entry should be deleted.
22-
func NewDeleteConfirm(entry string) survey.Prompt {
23-
prompt := &survey.Confirm{
24-
Message: "Are you sure you want to delete: " + entry,
25-
}
26-
return prompt
27-
}
28-
2921
// NewConfirm creates a prompt to confirm if the entry should be deleted.
3022
func NewConfirm(message string) survey.Prompt {
3123
prompt := &survey.Confirm{

0 commit comments

Comments
 (0)