Open shani1998 opened 2 months ago
👋 Thanks for reporting!
A maintainer will take a look at your issue shortly. 👀
In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.
⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9
📣 If you've already given us your feedback, you can still help by spreading the news, either by sharing the above link or telling people about this on Twitter:
https://twitter.com/sagikazarmark/status/1306904078967074816
Thank you! ❤️
I am also facing the same issue. I found a pattern where in two flags registered with same common prefix, then it is returning empty for the child flags. For example:
_ = pflag.String("akshay.barik.v1", "akshay barik v1 value", "some v1 description")
_ = pflag.String("akshay.barik", "akshay barik value", "some description")
fmt.Println(viper.GetString("akshay.barik.v1")) // getting empty
fmt.Println( viper.GetString("akshay.barik"))
I am also facing the same issue. I found a pattern where in two flags registered with same common prefix, then it is returning empty for the child flags. For example:
_ = pflag.String("akshay.barik.v1", "akshay barik v1 value", "some v1 description") _ = pflag.String("akshay.barik", "akshay barik value", "some description") fmt.Println(viper.GetString("akshay.barik.v1")) // getting empty fmt.Println( viper.GetString("akshay.barik"))
Thanks, Akshay, for noticing this pattern. I see the same pattern now. I initially thought it was specific to gateway.endpoint
, but it seems like multiple nested flags with a common prefix are having issues in Viper 1.18.0. Hopefully, we’ll get an update on this soon.
Preflight Checklist
Viper Version
1.18.0
Go Version
1.22.6
Config Source
Flags
Format
Other (specify below)
Repl.it link
No response
Code reproducing the issue
Expected Behavior
it should print:
Actual Behavior
in v1.17.0 it is working as expected returning output as
Steps To Reproduce
go mod
module test
go 1.22.4
require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.0 )
require ( github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect )