Skip to content

fix label of --id in admin delete user #14005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@ var (
}

microcmdUserDelete = cli.Command{
Name: "delete",
Usage: "Delete specific user",
Flags: []cli.Flag{idFlag},
Name: "delete",
Usage: "Delete specific user",
Flags: []cli.Flag{cli.Int64Flag{
Name: "id",
Usage: "ID of user",
}, cli.StringFlag{
Name: "username",
Usage: "Username",
}},
Action: runDeleteUser,
}

Expand Down Expand Up @@ -463,15 +469,21 @@ func runListUsers(c *cli.Context) error {
}

func runDeleteUser(c *cli.Context) error {
if !c.IsSet("id") {
return fmt.Errorf("--id flag is missing")
if !c.IsSet("id") && !c.IsSet("username") {
return fmt.Errorf("--id or --username missing")
}

if err := initDB(); err != nil {
return err
}

user, err := models.GetUserByID(c.Int64("id"))
var err error
var user *models.User
if c.IsSet("id") {
user, err = models.GetUserByID(c.Int64("id"))
} else {
user, err = models.GetUserByName(c.String("username"))
}
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion docs/content/doc/usage/command-line.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ Admin operations:
- `gitea admin user list`
- `delete`:
- Options:
- `--id`: ID of user to be deleted. Required.
- `--username`: Username of user to be deleted.
- `--id`: ID of user to be deleted.
- One of `--id` or `--username` is required.
- Examples:
- `gitea admin user delete --id 1`
- `create`: - Options: - `--name value`: Username. Required. As of gitea 1.9.0, use the `--username` flag instead. - `--username value`: Username. Required. New in gitea 1.9.0. - `--password value`: Password. Required. - `--email value`: Email. Required. - `--admin`: If provided, this makes the user an admin. Optional. - `--access-token`: If provided, an access token will be created for the user. Optional. (default: false). - `--must-change-password`: If provided, the created user will be required to choose a newer password after
Expand Down