Skip to content

Commit 5193dcb

Browse files
authored
feat: add ability to parse flags to the end (#814)
1 parent 31799a9 commit 5193dcb

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

1010
- Minimum Go version is now 1.21
1111
- Add Unwrap to PartialError (#815)
12+
- Allow flags anywhere on the CLI (#814)
13+
14+
`goose` uses the default Go `flag` parsing library, which means flags **must** be defined before the
15+
first positional argument. We've updated this behavior to allow flags to be defined anywhere. For
16+
more details, see [blog post](https://mfridman.com/blog/2024/allowing-flags-anywhere-on-the-cli/).
17+
1218
- Update `WithDisableGlobalRegistry` behavior (#783). When set, this will ignore globally-registered
1319
migrationse entirely instead of the previous behavior of raising an error. Specifically, the
1420
following check is removed:

cmd/goose/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"text/tabwriter"
1818
"text/template"
1919

20+
"github.com/mfridman/xflag"
2021
"github.com/pressly/goose/v3"
2122
"github.com/pressly/goose/v3/internal/cfg"
2223
"github.com/pressly/goose/v3/internal/migrationstats"
@@ -45,7 +46,8 @@ func main() {
4546
ctx := context.Background()
4647

4748
flags.Usage = usage
48-
if err := flags.Parse(os.Args[1:]); err != nil {
49+
50+
if err := xflag.ParseToEnd(flags, os.Args[1:]); err != nil {
4951
log.Fatalf("failed to parse args: %v", err)
5052
return
5153
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module github.com/pressly/goose/v3
22

3-
go 1.21
3+
go 1.21.0
44

55
require (
66
github.com/ClickHouse/clickhouse-go/v2 v2.27.1
77
github.com/go-sql-driver/mysql v1.8.1
88
github.com/jackc/pgx/v5 v5.6.0
99
github.com/mfridman/interpolate v0.0.2
10+
github.com/mfridman/xflag v0.0.0-20240825232106-efb77353e578
1011
github.com/microsoft/go-mssqldb v1.7.2
1112
github.com/sethvargo/go-retry v0.3.0
1213
github.com/stretchr/testify v1.9.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
151151
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
152152
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
153153
github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg=
154+
github.com/mfridman/xflag v0.0.0-20240825232106-efb77353e578 h1:CRrqlUmLebb/QjzRDWE0E66+YyN/v95+w6WyH9ju8/Y=
155+
github.com/mfridman/xflag v0.0.0-20240825232106-efb77353e578/go.mod h1:/483ywM5ZO5SuMVjrIGquYNE5CzLrj5Ux/LxWWnjRaE=
154156
github.com/microsoft/go-mssqldb v1.7.2 h1:CHkFJiObW7ItKTJfHo1QX7QBBD1iV+mn1eOyRP3b/PA=
155157
github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA=
156158
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=

0 commit comments

Comments
 (0)