2019-01-05 22:44:33 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
usersCmd.AddCommand(usersRmCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
var usersRmCmd = &cobra.Command{
|
2019-01-06 13:21:31 +00:00
|
|
|
Use: "rm <id|username>",
|
2019-01-05 22:44:33 +00:00
|
|
|
Short: "Delete a user by username or id",
|
|
|
|
Long: `Delete a user by username or id`,
|
2019-01-06 13:21:31 +00:00
|
|
|
Args: cobra.ExactArgs(1),
|
2019-01-05 22:44:33 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
db := getDB()
|
|
|
|
defer db.Close()
|
|
|
|
st := getStorage(db)
|
|
|
|
|
2019-01-06 13:21:31 +00:00
|
|
|
username, id := parseUsernameOrID(args[0])
|
2019-01-05 22:44:33 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
if username != "" {
|
|
|
|
err = st.Users.Delete(username)
|
|
|
|
} else {
|
|
|
|
err = st.Users.Delete(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
checkErr(err)
|
|
|
|
fmt.Println("user deleted successfully")
|
|
|
|
},
|
|
|
|
}
|