Example #1
0
func (c *User) Create(ctx *cli.Context) {
	email := ctx.Args().First()
	if email == "" {
		log.Fatalf("Please provide an email address.")
	}
	password := ctx.String("password")
	if password == "" {
		password = getPassword()
	}

	c.Ctx.Start()
	user, err := c.Ctx.Accounts.Create(uuid.New(), email, password, "{}")
	if err != nil {
		log.Fatalf("%s", err)
	}

	fmt.Printf(`Created user as "%s".`+"\n", user.GetID())

	if ctx.Bool("as-superuser") {
		if err := c.Ctx.Policies.Create(superUserPolicy(user.GetID())); err != nil {
			log.Fatalf("%s", err)
		}
		fmt.Printf(`Granted superuser privileges to user "%s".`+"\n", user.GetID())
	}
}