Ai
1 Star 0 Fork 0

ryancartoon/sensu-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
delete.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
package user
import (
"errors"
"fmt"
"github.com/sensu/sensu-go/cli"
"github.com/sensu/sensu-go/cli/commands/helpers"
"github.com/spf13/cobra"
)
// DeleteCommand adds a command that allows admin's to disable users
func DeleteCommand(cli *cli.SensuCli) *cobra.Command {
cmd := cobra.Command{
Use: "disable [USERNAME]",
Short: "disable user given username",
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("invalid argument(s) received")
}
username := args[0]
if skipConfirm, _ := cmd.Flags().GetBool("skip-confirm"); !skipConfirm {
dialog := helpers.ConfirmDestructiveOp{Op: "disable", Type: "user"}
if ok, err := dialog.Ask(username); !ok || err != nil {
fmt.Fprintln(cmd.OutOrStdout(), "Canceled")
return nil
}
}
err := cli.Client.DisableUser(username)
if err != nil {
return err
}
_, err = fmt.Fprintln(cmd.OutOrStdout(), "Disabled")
return err
},
}
_ = cmd.Flags().Bool("skip-confirm", false, "skip interactive confirmation prompt")
return &cmd
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ryancartoon/sensu-go.git
git@gitee.com:ryancartoon/sensu-go.git
ryancartoon
sensu-go
sensu-go
v5.10.1

搜索帮助