mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-11 23:50:04 +01:00
Update CLI action signatures. Closes #1
This commit is contained in:
parent
252cd4bdf1
commit
c0f0a5db8b
1 changed files with 22 additions and 43 deletions
41
main.go
41
main.go
|
|
@ -13,7 +13,10 @@ func main() {
|
|||
|
||||
app := NewApp()
|
||||
err := app.Run(os.Args)
|
||||
checkErr(err)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// NewApp creates a new command line app
|
||||
|
|
@ -40,44 +43,32 @@ func NewApp() *cli.App {
|
|||
{
|
||||
Name: "new",
|
||||
Usage: "Generate a new migration file",
|
||||
Action: func(ctx *cli.Context) {
|
||||
runCommand(NewCommand, ctx)
|
||||
},
|
||||
Action: NewCommand,
|
||||
},
|
||||
{
|
||||
Name: "up",
|
||||
Usage: "Create database (if necessary) and migrate to the latest version",
|
||||
Action: func(ctx *cli.Context) {
|
||||
runCommand(UpCommand, ctx)
|
||||
},
|
||||
Action: UpCommand,
|
||||
},
|
||||
{
|
||||
Name: "create",
|
||||
Usage: "Create database",
|
||||
Action: func(ctx *cli.Context) {
|
||||
runCommand(CreateCommand, ctx)
|
||||
},
|
||||
Action: CreateCommand,
|
||||
},
|
||||
{
|
||||
Name: "drop",
|
||||
Usage: "Drop database (if it exists)",
|
||||
Action: func(ctx *cli.Context) {
|
||||
runCommand(DropCommand, ctx)
|
||||
},
|
||||
Action: DropCommand,
|
||||
},
|
||||
{
|
||||
Name: "migrate",
|
||||
Usage: "Migrate to the latest version",
|
||||
Action: func(ctx *cli.Context) {
|
||||
runCommand(MigrateCommand, ctx)
|
||||
},
|
||||
Action: MigrateCommand,
|
||||
},
|
||||
{
|
||||
Name: "rollback",
|
||||
Usage: "Rollback the most recent migration",
|
||||
Action: func(ctx *cli.Context) {
|
||||
runCommand(RollbackCommand, ctx)
|
||||
},
|
||||
Action: RollbackCommand,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -86,11 +77,6 @@ func NewApp() *cli.App {
|
|||
|
||||
type command func(*cli.Context) error
|
||||
|
||||
func runCommand(cmd command, ctx *cli.Context) {
|
||||
err := cmd(ctx)
|
||||
checkErr(err)
|
||||
}
|
||||
|
||||
func loadDotEnv() {
|
||||
if _, err := os.Stat(".env"); err != nil {
|
||||
return
|
||||
|
|
@ -100,10 +86,3 @@ func loadDotEnv() {
|
|||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
}
|
||||
|
||||
func checkErr(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue