2019-01-06 06:44:33 +08:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
usersCmd.AddCommand(usersRmCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
var usersRmCmd = &cobra.Command{
|
2019-01-06 21:21:31 +08:00
|
|
|
Use: "rm <id|username>",
|
2019-01-06 06:44:33 +08:00
|
|
|
Short: "Delete a user by username or id",
|
|
|
|
Long: `Delete a user by username or id`,
|
2019-01-06 21:21:31 +08:00
|
|
|
Args: cobra.ExactArgs(1),
|
2024-04-02 00:24:06 +08:00
|
|
|
Run: python(func(_ *cobra.Command, args []string, d pythonData) {
|
2019-01-06 21:21:31 +08:00
|
|
|
username, id := parseUsernameOrID(args[0])
|
2019-01-06 06:44:33 +08:00
|
|
|
var err error
|
|
|
|
|
|
|
|
if username != "" {
|
2019-01-08 04:24:23 +08:00
|
|
|
err = d.store.Users.Delete(username)
|
2019-01-06 06:44:33 +08:00
|
|
|
} else {
|
2019-01-08 04:24:23 +08:00
|
|
|
err = d.store.Users.Delete(id)
|
2019-01-06 06:44:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
checkErr(err)
|
|
|
|
fmt.Println("user deleted successfully")
|
2019-01-08 04:24:23 +08:00
|
|
|
}, pythonConfig{}),
|
2019-01-06 06:44:33 +08:00
|
|
|
}
|