Skip to content

Commit

Permalink
Merge pull request #292 from systemli/Add-Command-for-deleting-a-User
Browse files Browse the repository at this point in the history
Add Command for deleting a User
  • Loading branch information
0x46616c6b authored Jan 1, 2024
2 parents 1c8e2c3 + 06deaf2 commit ab1be4b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,35 @@ var (
fmt.Printf("Password: %s\n", password)
},
}

userDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a user",
Run: func(cmd *cobra.Command, args []string) {
if email == "" {
log.Fatal("email is required")
}

user, err := store.FindUserByEmail(email)
if err != nil {
log.WithError(err).Fatal("could not find user")
}

if err := store.DeleteUser(user); err != nil {
log.WithError(err).Fatal("could not delete user")
}

fmt.Printf("Deleted user %s\n", email)
},
}
)

func init() {
userCmd.AddCommand(userCreateCmd)

userCreateCmd.Flags().StringVar(&email, "email", "", "email address of the user")
userCreateCmd.Flags().StringVar(&password, "password", "", "password of the user")
userCreateCmd.Flags().BoolVar(&isSuperAdmin, "super-admin", false, "make the user a super admin")

userCmd.AddCommand(userDeleteCmd)
userDeleteCmd.Flags().StringVar(&email, "email", "", "email address of the user")
}

0 comments on commit ab1be4b

Please sign in to comment.