mirror of
https://github.com/Fluffy-Bean/TastyBites.git
synced 2024-12-26 17:36:15 +00:00
46 lines
946 B
Go
46 lines
946 B
Go
package cmd
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/Fluffy-Bean/TastyBites/api"
|
|
db "github.com/Fluffy-Bean/TastyBites/database"
|
|
)
|
|
|
|
func run(flags []string) {
|
|
cmd := flag.NewFlagSet("run", flag.ExitOnError)
|
|
|
|
host := cmd.String("host", "127.0.0.1:8080", "Host address, such as 0.0.0.0:8080")
|
|
skip := cmd.Bool("skipMigrations", false, "Skip any pending migrations")
|
|
logging := cmd.Bool("log", false, "Enable logging for the application")
|
|
|
|
err := cmd.Parse(flags)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if !*skip {
|
|
pending, err := db.GetPending()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if pending {
|
|
fmt.Println("Pending migrations!")
|
|
fmt.Println("Run `TastyBites status` or use the flag -skipMigrations")
|
|
os.Exit(1)
|
|
}
|
|
} else {
|
|
fmt.Println("WARNING: Skipping migrations! This can lead to errors, or even data loss!")
|
|
}
|
|
|
|
api.Serve(api.Config{
|
|
Host: *host,
|
|
Logging: *logging,
|
|
})
|
|
}
|