/
delete.go
45 lines (39 loc) · 1.11 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package role
import (
"errors"
"fmt"
"github.com/sensu/sensu-go/cli"
"github.com/sensu/sensu-go/cli/commands/helpers"
"github.com/spf13/cobra"
)
// DeleteCommand defines new command to delete a role
func DeleteCommand(cli *cli.SensuCli) *cobra.Command {
cmd := &cobra.Command{
Use: "delete [NAME]",
Short: "delete a role with the given name",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
// If no name is present print out usage
if len(args) != 1 {
_ = cmd.Help()
return errors.New("a role name is required")
}
name := args[0]
namespace := cli.Config.Namespace()
if skipConfirm, _ := cmd.Flags().GetBool("skip-confirm"); !skipConfirm {
if confirmed := helpers.ConfirmDelete(name); !confirmed {
_, err := fmt.Fprintln(cmd.OutOrStdout(), "Canceled")
return err
}
}
err := cli.Client.DeleteRole(namespace, name)
if err != nil {
return err
}
_, err = fmt.Fprintln(cmd.OutOrStdout(), "Deleted")
return err
},
}
_ = cmd.Flags().Bool("skip-confirm", false, "skip interactive confirmation prompt")
return cmd
}