-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
viper and cobra sub commands #801
Comments
Unmarshaling works a bit differently than The different behavior is caused by the fact that internally not everything is a That's why sub does not return anything, and that's why unmarshaling doesn't work (neither way). Usually the solution is to set a default value. In your case you could do the following in your flag loop:
Hope that helps. |
It partially solves the issue but it looks like that flags are not taken into account but only values from env vars or configuration files are set when using
|
Yeah, |
I'm trying to write a tool for which I would let user set defaults or custom CLI arguments through a configuration file or env vars. What I've done so far is something like:
What the code does it to walk the command hierarchy and bind pflags to viper so as example the command
should be equivalent to
The problem I'm facing is that either
viper.UnmarshalKey("main.sub1, &sopt)
andviper.Sub("main.sub1").Unmarshal(&sopt)
fail (note that theSub
variant panics asSub
returnsnil
)The text was updated successfully, but these errors were encountered: