2017-05-15 13:59:26 +02:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/drone/drone-go/drone"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
|
|
|
"github.com/drone/drone-cli/drone/internal"
|
|
|
|
)
|
|
|
|
|
|
|
|
var userAddCmd = cli.Command{
|
2017-07-28 23:51:52 +02:00
|
|
|
Name: "add",
|
|
|
|
Usage: "adds a user",
|
|
|
|
ArgsUsage: "<username>",
|
|
|
|
Action: userAdd,
|
2018-09-21 01:04:58 +02:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "admin",
|
|
|
|
Usage: "admin privileged",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "machine",
|
|
|
|
Usage: "machine account",
|
|
|
|
},
|
2019-04-12 22:17:42 +02:00
|
|
|
cli.StringFlag{
|
2019-02-21 01:59:11 +01:00
|
|
|
Name: "token",
|
|
|
|
Usage: "api token",
|
|
|
|
},
|
2018-09-21 01:04:58 +02:00
|
|
|
},
|
2017-05-15 13:59:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func userAdd(c *cli.Context) error {
|
|
|
|
login := c.Args().First()
|
|
|
|
|
|
|
|
client, err := internal.NewClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-21 01:04:58 +02:00
|
|
|
in := &drone.User{
|
|
|
|
Login: login,
|
|
|
|
Admin: c.Bool("admin"),
|
|
|
|
Machine: c.Bool("machine"),
|
2019-02-21 01:59:11 +01:00
|
|
|
Token: c.String("token"),
|
2018-09-21 01:04:58 +02:00
|
|
|
}
|
|
|
|
user, err := client.UserCreate(in)
|
2017-05-15 13:59:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("Successfully added user %s\n", user.Login)
|
2019-02-21 01:59:11 +01:00
|
|
|
if user.Token != "" {
|
|
|
|
fmt.Printf("Generated account token %s\n", user.Token)
|
|
|
|
}
|
2017-05-15 13:59:26 +02:00
|
|
|
return nil
|
|
|
|
}
|