mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-12 08:00: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()
|
app := NewApp()
|
||||||
err := app.Run(os.Args)
|
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
|
// NewApp creates a new command line app
|
||||||
|
|
@ -40,44 +43,32 @@ func NewApp() *cli.App {
|
||||||
{
|
{
|
||||||
Name: "new",
|
Name: "new",
|
||||||
Usage: "Generate a new migration file",
|
Usage: "Generate a new migration file",
|
||||||
Action: func(ctx *cli.Context) {
|
Action: NewCommand,
|
||||||
runCommand(NewCommand, ctx)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "up",
|
Name: "up",
|
||||||
Usage: "Create database (if necessary) and migrate to the latest version",
|
Usage: "Create database (if necessary) and migrate to the latest version",
|
||||||
Action: func(ctx *cli.Context) {
|
Action: UpCommand,
|
||||||
runCommand(UpCommand, ctx)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "create",
|
Name: "create",
|
||||||
Usage: "Create database",
|
Usage: "Create database",
|
||||||
Action: func(ctx *cli.Context) {
|
Action: CreateCommand,
|
||||||
runCommand(CreateCommand, ctx)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "drop",
|
Name: "drop",
|
||||||
Usage: "Drop database (if it exists)",
|
Usage: "Drop database (if it exists)",
|
||||||
Action: func(ctx *cli.Context) {
|
Action: DropCommand,
|
||||||
runCommand(DropCommand, ctx)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "migrate",
|
Name: "migrate",
|
||||||
Usage: "Migrate to the latest version",
|
Usage: "Migrate to the latest version",
|
||||||
Action: func(ctx *cli.Context) {
|
Action: MigrateCommand,
|
||||||
runCommand(MigrateCommand, ctx)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "rollback",
|
Name: "rollback",
|
||||||
Usage: "Rollback the most recent migration",
|
Usage: "Rollback the most recent migration",
|
||||||
Action: func(ctx *cli.Context) {
|
Action: RollbackCommand,
|
||||||
runCommand(RollbackCommand, ctx)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,11 +77,6 @@ func NewApp() *cli.App {
|
||||||
|
|
||||||
type command func(*cli.Context) error
|
type command func(*cli.Context) error
|
||||||
|
|
||||||
func runCommand(cmd command, ctx *cli.Context) {
|
|
||||||
err := cmd(ctx)
|
|
||||||
checkErr(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadDotEnv() {
|
func loadDotEnv() {
|
||||||
if _, err := os.Stat(".env"); err != nil {
|
if _, err := os.Stat(".env"); err != nil {
|
||||||
return
|
return
|
||||||
|
|
@ -100,10 +86,3 @@ func loadDotEnv() {
|
||||||
log.Fatal("Error loading .env file")
|
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