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

Fix copy displayed when disabling users with sensuctl #2681

Merged
merged 3 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ in the presence cluster member failures and cluster restarts.
- Fixes a bug where generic store methods assumed a namespace was provided for non-namespaced resources.
- Keepalive and check TTL database state is now properly garbage-collected on
entity deletion.

### Fixed
- Fixed a bug where `sensuctl version` required configuration files to exist.
- Updates the copy on the confirm disable dialog to accurately reflect the
operation.

## [5.1.1] - 2019-01-24

Expand Down
48 changes: 43 additions & 5 deletions cli/commands/helpers/prompts.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,61 @@
package helpers

import (
"fmt"

"github.com/AlecAivazis/survey"
"github.com/sensu/sensu-go/cli/elements/globals"
)

// ConfirmDelete confirm a deletion operation before it is completed.
func ConfirmDelete(name string) bool {
question := globals.TitleStyle("Are you sure you would like to ") + globals.CTATextStyle("delete") + globals.TitleStyle(" resource '") + globals.PrimaryTextStyle(name) + globals.TitleStyle("'?")
confirm := &ConfirmDestructiveOp{
Type: "resource",
Op: "delete",
}
ok, _ := confirm.Ask(name)
return ok
}

confirmation := false
prompt := &survey.Confirm{
// ConfirmDestructiveOp presents prompt for a destructive operation.
type ConfirmDestructiveOp struct {
Type string
Op string
}

// Ask presents prompt confirming a destructive operation.
func (c *ConfirmDestructiveOp) Ask(name string) (bool, error) {
question := globals.TitleStyle("Are you sure you would like to ") +
globals.CTATextStyle(c.Op) +
globals.TitleStyle(fmt.Sprintf(" %s '", c.Type)) +
globals.PrimaryTextStyle(name) +
globals.TitleStyle("'?")

confirm := &Confirm{
Message: question,
Default: false,
}
return confirm.Ask()
}

// Confirm an operation before it is completed
type Confirm struct {
Message string
Default bool
}

// Ask executes confirmation of operation
func (c *Confirm) Ask() (bool, error) {
prompt := &survey.Confirm{
Message: c.Message,
Default: c.Default,
}

confirmation := false
err := survey.AskOne(prompt, &confirmation, nil)
if err != nil {
return false
return false, err
}

return confirmation
return confirmation, nil
}
3 changes: 2 additions & 1 deletion cli/commands/user/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func DeleteCommand(cli *cli.SensuCli) *cobra.Command {

username := args[0]
if skipConfirm, _ := cmd.Flags().GetBool("skip-confirm"); !skipConfirm {
if confirmed := helpers.ConfirmDelete(username); !confirmed {
dialog := helpers.ConfirmDestructiveOp{Op: "disable", Type: "user"}
if ok, err := dialog.Ask(username); !ok || err != nil {
fmt.Fprintln(cmd.OutOrStdout(), "Canceled")
return nil
}
Expand Down