Skip to content

Commit

Permalink
Update dependencies: cli v2
Browse files Browse the repository at this point in the history
- Alternate solution to resolve issue amacneil#106
  • Loading branch information
Gonzalo Lucero committed Dec 14, 2019
1 parent 810bdda commit e583fe9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/lib/pq v1.2.0
github.com/mattn/go-sqlite3 v1.11.0
github.com/stretchr/testify v1.4.0
github.com/urfave/cli v1.22.1
github.com/urfave/cli/v2 v2.0.0
google.golang.org/appengine v1.6.2 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.0.0 h1:+HU9SCbu8GnEUFtIBfuUNXN39ofWViIEJIp6SURMpCg=
github.com/urfave/cli/v2 v2.0.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down
41 changes: 22 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/amacneil/dbmate/pkg/dbmate"
"github.com/joho/godotenv"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func main() {
Expand All @@ -30,28 +30,31 @@ func NewApp() *cli.App {
app.Version = dbmate.Version

app.Flags = []cli.Flag{
cli.StringFlag{
Name: "env, e",
Value: "DATABASE_URL",
Usage: "specify an environment variable containing the database URL",
&cli.StringFlag{
Name: "env",
Aliases: []string{"e"},
Value: "DATABASE_URL",
Usage: "specify an environment variable containing the database URL",
},
cli.StringFlag{
Name: "migrations-dir, d",
Value: dbmate.DefaultMigrationsDir,
Usage: "specify the directory containing migration files",
&cli.StringFlag{
Name: "migrations-dir",
Aliases: []string{"d"},
Value: dbmate.DefaultMigrationsDir,
Usage: "specify the directory containing migration files",
},
cli.StringFlag{
Name: "schema-file, s",
Value: dbmate.DefaultSchemaFile,
Usage: "specify the schema file location",
&cli.StringFlag{
Name: "schema-file",
Aliases: []string{"s"},
Value: dbmate.DefaultSchemaFile,
Usage: "specify the schema file location",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "no-dump-schema",
Usage: "don't update the schema file on migrate/rollback",
},
}

app.Commands = []cli.Command{
app.Commands = []*cli.Command{
{
Name: "new",
Aliases: []string{"n"},
Expand Down Expand Up @@ -135,17 +138,17 @@ func action(f func(*dbmate.DB, *cli.Context) error) cli.ActionFunc {
return err
}
db := dbmate.New(u)
db.AutoDumpSchema = !c.GlobalBool("no-dump-schema")
db.MigrationsDir = c.GlobalString("migrations-dir")
db.SchemaFile = c.GlobalString("schema-file")
db.AutoDumpSchema = !c.Bool("no-dump-schema")
db.MigrationsDir = c.String("migrations-dir")
db.SchemaFile = c.String("schema-file")

return f(db, c)
}
}

// getDatabaseURL returns the current environment database url
func getDatabaseURL(c *cli.Context) (u *url.URL, err error) {
env := c.GlobalString("env")
env := c.String("env")
value := os.Getenv(env)

return url.Parse(value)
Expand Down
5 changes: 3 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func testContext(t *testing.T, u *url.URL) *cli.Context {
Expand All @@ -17,7 +17,8 @@ func testContext(t *testing.T, u *url.URL) *cli.Context {
app := NewApp()
flagset := flag.NewFlagSet(app.Name, flag.ContinueOnError)
for _, f := range app.Flags {
f.Apply(flagset)
err := f.Apply(flagset)
require.NoError(t, err)
}

return cli.NewContext(app, flagset, nil)
Expand Down

0 comments on commit e583fe9

Please sign in to comment.