From 3ada74c4db61c90ba428a071282fdacfd038cfc0 Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 21 Feb 2024 13:52:22 +0000 Subject: [PATCH] feat: replace ff with with flagconf --- cmd/gonic/gonic.go | 29 ++++++++++------------------- go.mod | 3 +-- go.sum | 12 ++++++------ 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 565ee519..b3bc283c 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -1,4 +1,4 @@ -//nolint:lll,gocyclo,forbidigo,nilerr +//nolint:lll,gocyclo,forbidigo,nilerr,errcheck package main import ( @@ -26,10 +26,10 @@ import ( "github.com/google/shlex" "github.com/gorilla/securecookie" _ "github.com/jinzhu/gorm/dialects/sqlite" - "github.com/peterbourgon/ff/v4" "github.com/sentriz/gormstore" "golang.org/x/sync/errgroup" + "go.senan.xyz/flagconf" "go.senan.xyz/gonic" "go.senan.xyz/gonic/db" "go.senan.xyz/gonic/handlerutil" @@ -78,7 +78,7 @@ func main() { confHTTPLog := flag.Bool("http-log", true, "http request logging (optional)") confShowVersion := flag.Bool("version", false, "show gonic version") - _ = flag.String("config-path", "", "path to config (optional)") + confConfigPath := flag.String("config-path", "", "path to config (optional)") confExcludePattern := flag.String("exclude-pattern", "", "regex pattern to exclude files from scan (optional)") @@ -92,28 +92,19 @@ func main() { deprecatedConfGenreSplit := flag.String("genre-split", "", "(deprecated, see multi-value settings)") - if _, err := regexp.Compile(*confExcludePattern); err != nil { - log.Fatalf("invalid exclude pattern: %v\n", err) - } - - switch err := ff.Parse(flag.CommandLine, os.Args[1:], - ff.WithConfigFileFlag("config-path"), - ff.WithConfigFileParser(ff.PlainParser), - ff.WithEnvVarPrefix(gonic.NameUpper), - ff.WithEnvVarSplit(","), - ); { - case errors.Is(err, ff.ErrHelp): - flag.Usage() - os.Exit(0) - case err != nil: - log.Fatalf("error parsing flags: %v", err) - } + flag.Parse() + flagconf.ParseEnv() + flagconf.ParseConfig(*confConfigPath) if *confShowVersion { fmt.Printf("v%s\n", gonic.Version) os.Exit(0) } + if _, err := regexp.Compile(*confExcludePattern); err != nil { + log.Fatalf("invalid exclude pattern: %v\n", err) + } + if len(confMusicPaths) == 0 { log.Fatalf("please provide a music directory") } diff --git a/go.mod b/go.mod index 7452e8df..3c9a01a2 100644 --- a/go.mod +++ b/go.mod @@ -20,12 +20,12 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/mmcdole/gofeed v1.2.1 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 - github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4 github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 github.com/stretchr/testify v1.8.4 + go.senan.xyz/flagconf v0.0.0-20240221142506-c693ad2c2dc1 golang.org/x/exp v0.0.0-20240213143201-ec583247a57a golang.org/x/net v0.21.0 golang.org/x/sync v0.6.0 @@ -58,7 +58,6 @@ require ( github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect golang.org/x/crypto v0.19.0 // indirect golang.org/x/image v0.15.0 // indirect diff --git a/go.sum b/go.sum index ef0a978a..7a37adc2 100644 --- a/go.sum +++ b/go.sum @@ -116,10 +116,6 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= -github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= -github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4 h1:aq3I2fGN1Yr5SMYybLYnw49T+xckxkVgSfBU2xk1KTs= -github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4/go.mod h1:H/13DK46DKXy7EaIxPhk2Y0EC8aubKm35nBjBe8AAGc= github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 h1:SvVjZyjXBOjqjCdMiC9ndyWb709aP5qU4Qbun40GCxA= github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4/go.mod h1:Mpa6Hci7lO3vybfdYlWXmH5gEq2vyOmYYjhrlwCTW3w= 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 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 h1:aecPwcrY8mYmZmd9XgQcG8aILRuhRxeQMSunnr6DQ3U= github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743/go.mod h1:Zoo4UP5t2ySbPwScJfoydAlLLBonoqntv4ovA1T91Z8= 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 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.senan.xyz/flagconf v0.0.0-20240221142506-c693ad2c2dc1 h1:O3uSiZbK2TmPUCsw5Kz0pGeTKlJltoSxgxX+0M7I/9I= +go.senan.xyz/flagconf v0.0.0-20240221142506-c693ad2c2dc1/go.mod h1:B285qDMTH54V1G1OApPj0JhnQGpJXuFsN7XEFHGMQ1U= golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 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 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= +golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=