Skip to content

Commit

Permalink
feat(cmd): support cli flag for creating admin account
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Dec 21, 2023
1 parent d542e98 commit 04cf137
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ func NewAdminCommand(app *ArtalkCmd) *cobra.Command {
fmt.Println(" " + i18n.T("Create admin account"))
fmt.Println("--------------------------------")

username, email, password, err := credentials()
if err != nil {
log.Fatal(err)
// get from flags
username, _ := cmd.Flags().GetString("name")
email, _ := cmd.Flags().GetString("email")
password, _ := cmd.Flags().GetString("password")

if username == "" || email == "" || password == "" {
var err error
username, email, password, err = credentials()
if err != nil {
log.Fatal(err)
}
}

findUser := app.Dao().FindUser(username, email)
Expand Down Expand Up @@ -62,6 +70,10 @@ func NewAdminCommand(app *ArtalkCmd) *cobra.Command {
},
}

flag(adminCmd, "name", "", i18n.T("Username"))
flag(adminCmd, "email", "", i18n.T("Email"))
flag(adminCmd, "password", "", i18n.T("Password"))

return adminCmd
}

Expand Down

0 comments on commit 04cf137

Please sign in to comment.