func cliCreate(c *cli.CLI, d db.DB) cli.CommandFunc { return func(args ...string) (cli.Response, error) { var ( createArgs = make(map[string]string) email string pwhash string err error none = cli.Response("") rl = c.Rl ) if rl == nil { return none, errors.New("tried to create admin using nil readline") } for _, arg := range args { splt := strings.SplitN(arg, "=", 2) if len(splt) < 2 { return "", errors.New("create args must be of the form pw=foo email=bar") } createArgs[splt[0]] = splt[1] } email, ok := createArgs["email"] if !ok { email, err = getAdminEmail(rl, d) if err != nil { return none, err } } pw, ok := createArgs["pw"] if !ok { var b []byte b, err = rl.ReadPassword("Enter password: "******"key: " + string(key)), nil } }
func cliDelete(d db.DB) cli.CommandFunc { return func(args ...string) (cli.Response, error) { if len(args) != 1 { return "", errors.New("delete takes an email as its arg") } if err := admin.DeleteByEmail(d, args[0]); err != nil { return "", err } return cli.Response(fmt.Sprintf("admin %s deleted ok", args[0])), nil } }