2024-04-03 09:05:12 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reCoreD-UI/controllers"
|
2024-04-09 08:28:18 +00:00
|
|
|
"reCoreD-UI/database"
|
2024-04-03 09:05:12 +00:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var UserCommand *cli.Command
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
UserCommand = &cli.Command{
|
|
|
|
Name: "user",
|
|
|
|
Usage: "set admin username and password",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "username",
|
|
|
|
Aliases: []string{"u"},
|
|
|
|
Value: "amdin",
|
|
|
|
Usage: "admin username",
|
|
|
|
EnvVars: []string{"RECORED_ADMIN_USERNAME"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "passowrd",
|
|
|
|
Aliases: []string{"p"},
|
|
|
|
Required: true,
|
|
|
|
Usage: "admin password",
|
|
|
|
EnvVars: []string{"RECORED_ADMIN_PASSWORD"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: setUser,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func setUser(c *cli.Context) error {
|
2024-04-09 08:28:18 +00:00
|
|
|
if err := database.Connect(c.String("mysql-dsn")); err != nil {
|
2024-04-03 09:05:12 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-04-09 08:28:18 +00:00
|
|
|
return controllers.SetupAdmin(c.String("username"), c.String("password"))
|
2024-04-03 09:05:12 +00:00
|
|
|
}
|