Skip to content

Commit c56741a

Browse files
committed
feat: replace ff with with flagconf
1 parent 2878b88 commit c56741a

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

cmd/gonic/gonic.go

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//nolint:lll,gocyclo,forbidigo,nilerr
1+
//nolint:lll,gocyclo,forbidigo,nilerr,errcheck
22
package main
33

44
import (
@@ -26,10 +26,10 @@ import (
2626
"github.com/google/shlex"
2727
"github.com/gorilla/securecookie"
2828
_ "github.com/jinzhu/gorm/dialects/sqlite"
29-
"github.com/peterbourgon/ff/v4"
3029
"github.com/sentriz/gormstore"
3130
"golang.org/x/sync/errgroup"
3231

32+
"go.senan.xyz/flagconf"
3333
"go.senan.xyz/gonic"
3434
"go.senan.xyz/gonic/db"
3535
"go.senan.xyz/gonic/handlerutil"
@@ -78,7 +78,7 @@ func main() {
7878
confHTTPLog := flag.Bool("http-log", true, "http request logging (optional)")
7979

8080
confShowVersion := flag.Bool("version", false, "show gonic version")
81-
_ = flag.String("config-path", "", "path to config (optional)")
81+
confConfigPath := flag.String("config-path", "", "path to config (optional)")
8282

8383
confExcludePattern := flag.String("exclude-pattern", "", "regex pattern to exclude files from scan (optional)")
8484

@@ -92,28 +92,19 @@ func main() {
9292

9393
deprecatedConfGenreSplit := flag.String("genre-split", "", "(deprecated, see multi-value settings)")
9494

95-
if _, err := regexp.Compile(*confExcludePattern); err != nil {
96-
log.Fatalf("invalid exclude pattern: %v\n", err)
97-
}
98-
99-
switch err := ff.Parse(flag.CommandLine, os.Args[1:],
100-
ff.WithConfigFileFlag("config-path"),
101-
ff.WithConfigFileParser(ff.PlainParser),
102-
ff.WithEnvVarPrefix(gonic.NameUpper),
103-
ff.WithEnvVarSplit(","),
104-
); {
105-
case errors.Is(err, ff.ErrHelp):
106-
flag.Usage()
107-
os.Exit(0)
108-
case err != nil:
109-
log.Fatalf("error parsing flags: %v", err)
110-
}
95+
flag.Parse()
96+
flagconf.ParseEnv()
97+
flagconf.ParseConfig(*confConfigPath)
11198

11299
if *confShowVersion {
113100
fmt.Printf("v%s\n", gonic.Version)
114101
os.Exit(0)
115102
}
116103

104+
if _, err := regexp.Compile(*confExcludePattern); err != nil {
105+
log.Fatalf("invalid exclude pattern: %v\n", err)
106+
}
107+
117108
if len(confMusicPaths) == 0 {
118109
log.Fatalf("please provide a music directory")
119110
}

go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module go.senan.xyz/gonic
22

3-
go 1.21
3+
go 1.22.0
44

55
require (
66
github.com/Masterminds/sprig v2.22.0+incompatible
@@ -20,12 +20,12 @@ require (
2020
github.com/mitchellh/mapstructure v1.5.0
2121
github.com/mmcdole/gofeed v1.2.1
2222
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
23-
github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4
2423
github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4
2524
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be
2625
github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743
2726
github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981
2827
github.com/stretchr/testify v1.8.4
28+
go.senan.xyz/flagconf v0.0.0-20240221134952-1045a69d5f2c
2929
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
3030
golang.org/x/net v0.21.0
3131
golang.org/x/sync v0.6.0
@@ -58,7 +58,6 @@ require (
5858
github.com/olekukonko/tablewriter v0.0.5 // indirect
5959
github.com/pmezard/go-difflib v1.0.0 // indirect
6060
github.com/rivo/uniseg v0.4.7 // indirect
61-
github.com/rogpeppe/go-internal v1.11.0 // indirect
6261
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
6362
golang.org/x/crypto v0.19.0 // indirect
6463
golang.org/x/image v0.15.0 // indirect

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6
116116
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
117117
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
118118
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
119-
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
120-
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
121-
github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4 h1:aq3I2fGN1Yr5SMYybLYnw49T+xckxkVgSfBU2xk1KTs=
122-
github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4/go.mod h1:H/13DK46DKXy7EaIxPhk2Y0EC8aubKm35nBjBe8AAGc=
123119
github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 h1:SvVjZyjXBOjqjCdMiC9ndyWb709aP5qU4Qbun40GCxA=
124120
github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4/go.mod h1:Mpa6Hci7lO3vybfdYlWXmH5gEq2vyOmYYjhrlwCTW3w=
125121
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -129,8 +125,8 @@ github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDF
129125
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
130126
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
131127
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
132-
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
133-
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
128+
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
129+
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
134130
github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 h1:aecPwcrY8mYmZmd9XgQcG8aILRuhRxeQMSunnr6DQ3U=
135131
github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743/go.mod h1:Zoo4UP5t2ySbPwScJfoydAlLLBonoqntv4ovA1T91Z8=
136132
github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 h1:sLILANWN76ja66/K4k/mBqJuCjDZaM67w+Ru6rEB0s0=
@@ -142,6 +138,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
142138
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
143139
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
144140
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
141+
go.senan.xyz/flagconf v0.0.0-20240221134952-1045a69d5f2c h1:FDiRSLQ/lArg1/vcD7qnuerNIg1aaFB1c9lCva+PRLc=
142+
go.senan.xyz/flagconf v0.0.0-20240221134952-1045a69d5f2c/go.mod h1:TF5C+yTGoDFOSm3KUv8ezD9ygrFonYvzwuitzKLPYWw=
145143
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
146144
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
147145
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -203,6 +201,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
203201
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
204202
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
205203
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
204+
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
205+
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
206206
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
207207
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
208208
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)