Merge pull request #2 from amacneil/fix-deprecation-warnings

Update CLI action signatures
This commit is contained in:
Adrian Macneil 2016-08-07 22:47:18 -07:00 committed by GitHub
commit df712a3e98
2 changed files with 23 additions and 44 deletions

View file

@ -1,4 +1,4 @@
FROM golang:1.6.2
FROM golang:1.6.3
ENV CGO_ENABLED 1

41
main.go
View file

@ -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)
}
}