*: support deleting user in v3 auth

This commit adds a functionality of user deletion. It can be invoked
with the new user delete command.

Example usage:
$ ETCDCTL_API=3 etcdctl user delete usr1
This commit is contained in:
Hitoshi Mitake
2016-03-31 11:29:47 +09:00
parent 93c3f920ca
commit d8888ded12
12 changed files with 183 additions and 20 deletions

View File

@ -31,6 +31,7 @@ func NewUserCommand() *cobra.Command {
}
ac.AddCommand(NewUserAddCommand())
ac.AddCommand(NewUserDeleteCommand())
return ac
}
@ -51,6 +52,14 @@ func NewUserAddCommand() *cobra.Command {
return &cmd
}
func NewUserDeleteCommand() *cobra.Command {
return &cobra.Command{
Use: "delete <user name>",
Short: "delete a user",
Run: userDeleteCommandFunc,
}
}
// userAddCommandFunc executes the "user add" command.
func userAddCommandFunc(cmd *cobra.Command, args []string) {
if len(args) != 1 {
@ -89,3 +98,15 @@ func userAddCommandFunc(cmd *cobra.Command, args []string) {
ExitWithError(ExitError, err)
}
}
// userDeleteCommandFunc executes the "user delete" command.
func userDeleteCommandFunc(cmd *cobra.Command, args []string) {
if len(args) != 1 {
ExitWithError(ExitBadArgs, fmt.Errorf("user delete command requires user name as its argument."))
}
_, err := mustClientFromCmd(cmd).Auth.UserDelete(context.TODO(), args[0])
if err != nil {
ExitWithError(ExitError, err)
}
}