add seed_database command

This commit is contained in:
Danny van Kooten 2016-12-08 21:07:24 +01:00
parent 549b4bb055
commit 28a65501af
2 changed files with 15 additions and 0 deletions

View File

@ -7,18 +7,22 @@ import(
var runCreateUserCommand bool var runCreateUserCommand bool
var runDeleteUserCommand bool var runDeleteUserCommand bool
var runStartServerCommand bool var runStartServerCommand bool
var runSeedDatabaseCommand bool
var idArg int var idArg int
var emailArg string var emailArg string
var passwordArg string var passwordArg string
var nArg int
func Parse() { func Parse() {
// parse commands // parse commands
flag.BoolVar(&runCreateUserCommand, "create_user", false, "Create a new user") flag.BoolVar(&runCreateUserCommand, "create_user", false, "Create a new user")
flag.BoolVar(&runDeleteUserCommand, "delete_user", false, "Deletes a user") flag.BoolVar(&runDeleteUserCommand, "delete_user", false, "Deletes a user")
flag.BoolVar(&runStartServerCommand, "start_server", true, "Start the API web server") flag.BoolVar(&runStartServerCommand, "start_server", true, "Start the API web server")
flag.BoolVar(&runSeedDatabaseCommand, "seed_database", false, "Seed the database -n times")
flag.StringVar(&emailArg, "email", "", "Email address") flag.StringVar(&emailArg, "email", "", "Email address")
flag.StringVar(&passwordArg, "password", "", "Password") flag.StringVar(&passwordArg, "password", "", "Password")
flag.IntVar(&idArg, "id", 0, "Object ID") flag.IntVar(&idArg, "id", 0, "Object ID")
flag.IntVar(&nArg, "n", 0, "Number")
flag.Parse() flag.Parse()
} }
@ -27,6 +31,8 @@ func Run() {
createUser() createUser()
} else if runDeleteUserCommand { } else if runDeleteUserCommand {
deleteUser() deleteUser()
} else if runSeedDatabaseCommand {
seedDatabase()
} else if runStartServerCommand { } else if runStartServerCommand {
startServer() startServer()
} }

9
commands/seed.go Normal file
View File

@ -0,0 +1,9 @@
package commands
import(
"github.com/dannyvankooten/ana/db"
)
func seedDatabase() {
db.Seed(nArg)
}