Open vrtexe opened 1 month ago
Very interesting. Thanks for reporting. I also just did some testing, and setting default values for these options seem to fix the problem. That's a bit odd, but it works (see #168). I will probably merge the workaround for the top-level keys, but it would be great to have a better idea on why this is happening.
I just merged #168 as a temporary fix. #169 will come in due time.
Running the following command:
The WD_AUTH and WD_PREFIX seem to be parsed correctly and the problem i experienced was that the WD_MODIFY and WD_SCOPE were not working, after doing some analysis, the problem might occur because the
Permission
is nested withinConfig
, while this works for parsing in the default way with flags and config file, it does not work with environment variables.Possible solution i tried that might work would be to use something like
v.BindEnv("field")
, looking at the tests of the library used for loading configurations, specifically this one: https://github.com/spf13/viper/blob/cc53fac037475edaec5cd2cae73e6c3cc5caef9e/viper_test.go#L967, seems to fix this nesting issue however that feature is still not shipped.And as it states in their documentation here, that with
AutomaticEnv
only loads the value when av.Get("FIELD")
is called, and they probably do not call it for the nested structures, when they get the keys it only reads the 'outside' values during unmarshaling.