mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 19:11:58 +01:00
Add username flag in create-user command (#6534)
* Add username flag in create-user command * Fix the error message * Change name to username on flag of create-user command * Include create-user flags of both versions * delete deprecated example of create-user command
This commit is contained in:
parent
8e949db3b5
commit
2b9b3310f6
2 changed files with 25 additions and 5 deletions
25
cmd/admin.go
25
cmd/admin.go
|
@ -42,6 +42,10 @@ var (
|
|||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "Username. DEPRECATED: use username instead",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "Username",
|
||||
},
|
||||
cli.StringFlag{
|
||||
|
@ -288,14 +292,29 @@ func runChangePassword(c *cli.Context) error {
|
|||
}
|
||||
|
||||
func runCreateUser(c *cli.Context) error {
|
||||
if err := argsSet(c, "name", "email"); err != nil {
|
||||
if err := argsSet(c, "email"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.IsSet("name") && c.IsSet("username") {
|
||||
return errors.New("Cannot set both --name and --username flags")
|
||||
}
|
||||
if !c.IsSet("name") && !c.IsSet("username") {
|
||||
return errors.New("One of --name or --username flags must be set")
|
||||
}
|
||||
|
||||
if c.IsSet("password") && c.IsSet("random-password") {
|
||||
return errors.New("cannot set both -random-password and -password flags")
|
||||
}
|
||||
|
||||
var username string
|
||||
if c.IsSet("username") {
|
||||
username = c.String("username")
|
||||
} else {
|
||||
username = c.String("name")
|
||||
fmt.Fprintf(os.Stderr, "--name flag is deprecated. Use --username instead.\n")
|
||||
}
|
||||
|
||||
var password string
|
||||
|
||||
if c.IsSet("password") {
|
||||
|
@ -334,7 +353,7 @@ func runCreateUser(c *cli.Context) error {
|
|||
}
|
||||
|
||||
if err := models.CreateUser(&models.User{
|
||||
Name: c.String("name"),
|
||||
Name: username,
|
||||
Email: c.String("email"),
|
||||
Passwd: password,
|
||||
IsActive: true,
|
||||
|
@ -345,7 +364,7 @@ func runCreateUser(c *cli.Context) error {
|
|||
return fmt.Errorf("CreateUser: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("New user '%s' has been successfully created!\n", c.String("name"))
|
||||
fmt.Printf("New user '%s' has been successfully created!\n", username)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,8 @@ Admin operations:
|
|||
- Commands:
|
||||
- `create-user`
|
||||
- Options:
|
||||
- `--name value`: Username. Required.
|
||||
- `--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.
|
||||
|
@ -63,7 +64,7 @@ Admin operations:
|
|||
- `--random-password-length`: If provided, it will be used to configure the length of the randomly
|
||||
generated password. Optional. (default: 12)
|
||||
- Examples:
|
||||
- `gitea admin create-user --name myname --password asecurepassword --email me@example.com`
|
||||
- `gitea admin create-user --username myname --password asecurepassword --email me@example.com`
|
||||
- `change-password`
|
||||
- Options:
|
||||
- `--username value`, `-u value`: Username. Required.
|
||||
|
|
Loading…
Reference in a new issue