From 28a65501aff3e62c4f1004c11f49c1749e39d564 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Thu, 8 Dec 2016 21:07:24 +0100 Subject: [PATCH] add seed_database command --- commands/commands.go | 6 ++++++ commands/seed.go | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 commands/seed.go diff --git a/commands/commands.go b/commands/commands.go index d4830df..7337c01 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -7,18 +7,22 @@ import( var runCreateUserCommand bool var runDeleteUserCommand bool var runStartServerCommand bool +var runSeedDatabaseCommand bool var idArg int var emailArg string var passwordArg string +var nArg int func Parse() { // parse commands flag.BoolVar(&runCreateUserCommand, "create_user", false, "Create a new user") flag.BoolVar(&runDeleteUserCommand, "delete_user", false, "Deletes a user") 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(&passwordArg, "password", "", "Password") flag.IntVar(&idArg, "id", 0, "Object ID") + flag.IntVar(&nArg, "n", 0, "Number") flag.Parse() } @@ -27,6 +31,8 @@ func Run() { createUser() } else if runDeleteUserCommand { deleteUser() + } else if runSeedDatabaseCommand { + seedDatabase() } else if runStartServerCommand { startServer() } diff --git a/commands/seed.go b/commands/seed.go new file mode 100644 index 0000000..707a6fd --- /dev/null +++ b/commands/seed.go @@ -0,0 +1,9 @@ +package commands + +import( + "github.com/dannyvankooten/ana/db" +) + +func seedDatabase() { + db.Seed(nArg) +}