Replies: 1 comment 1 reply
-
If you move the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a CLI for which I'm using viper, and I wanted to be able to set a configuration value from either a config file (YAML) or a flag. Naturally, I figured that I can use an alias so both drive the same value in the
Viper
instance. However, I'm finding, like in #1598, that the flag being passed seems to have no effect on the underlying value it's aliased to.The relevant code to reproduce this is something like:
The output of both
println
statements isfalse
, whereas I'd expect both to betrue
, since the flag--override-flag
was passed, and is aliased toreal-flag
. The full example code can be found here: https://replit.com/@shreyb3/ViperPFlagRegisterAlias.This is a little bit of a rehash of #1598, because while I agree that that author's solution works to resolve this, this behavior doesn't seem to be explicitly called out in the documentation, so I'm not sure if it's the expected behavior of the library. Looking at the underlying library code from v1.19.0 (https://github.com/spf13/viper/blob/v1.19.0/viper.go#L1538), it seems that registering an alias does not affect what
viper.Get()
returns for pflag-set values and environment-set configuration values.So my question is: Is
RegisterAlias
supposed to not apply to flag-set values?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions