package cmd import ( "log" "os" cli "github.com/jawher/mow.cli" "bitmask.me/skeleton/internal/app" "bitmask.me/skeleton/internal/database" "bitmask.me/skeleton/internal/web" ) // Execute is the main entrypoint for this program func Execute() { var ac = app.New(app.ConfigFromEnv()) root := cli.App("skeleton", "") root.Command("web server", "run a web server", func(cmd *cli.Cmd) { cmd.Spec = "[ --http ]" var ( listenAddr = cmd.StringOpt("l addr http", ":8080", "Listen address") ) cmd.Action = func() { log.Printf("Web Server listening on %s", *listenAddr) web.RunServer(ac, *listenAddr) } }) root.Command("migrate", "alter the database schema", func(cmd *cli.Cmd) { cmd.Spec = "--up | --revision | --drop-all" var ( _ = cmd.BoolOpt("u up", false, "migrate to most recent revision") drop = cmd.BoolOpt("drop-all", false, "USE WITH CARE: Completely devestate the database, use --revision=0 instead") rev = cmd.IntOpt("r revision", database.MigrateUp, "revision that should be migrated to, defaults to most recent") ) cmd.Action = func() { db := ac.Database() if *drop { *rev = database.MigrateDrop } if err := database.Migrate(db, ac.Files, *rev); err != nil { log.Fatalf("Migration failed due to error: %s", err) } } }) root.Run(os.Args) }