mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
40 lines
779 B
Go
40 lines
779 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
usersCmd.AddCommand(usersRmCmd)
|
|
usersRmCmd.Flags().StringP("username", "u", "", "username to delete")
|
|
usersRmCmd.Flags().UintP("id", "i", 0, "id to delete")
|
|
}
|
|
|
|
var usersRmCmd = &cobra.Command{
|
|
Use: "rm",
|
|
Short: "Delete a user by username or id",
|
|
Long: `Delete a user by username or id`,
|
|
Args: usernameOrIDRequired,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
db := getDB()
|
|
defer db.Close()
|
|
st := getStorage(db)
|
|
|
|
username, _ := cmd.Flags().GetString("username")
|
|
id, _ := cmd.Flags().GetUint("id")
|
|
|
|
var err error
|
|
|
|
if username != "" {
|
|
err = st.Users.Delete(username)
|
|
} else {
|
|
err = st.Users.Delete(id)
|
|
}
|
|
|
|
checkErr(err)
|
|
fmt.Println("user deleted successfully")
|
|
},
|
|
}
|