How to use Viper with Cobra? #1061
-
There is a lot of confusion around using Viper and Cobra together and a lot of issues seem to land in the Viper repo, but this is actually more of an integration question on the Cobra side. This thread is supposed to provide some clues and should be a goto source for users. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Historically both Viper and Cobra originate from Hugo, a static page generator, but the individual libraries don't have any tight integration between them. This might change in the future though: with Viper 2, consumers (like Cobra) will have much more control over how they integrate with Viper. Nevertheless, it'll still be Cobra's job to handle the integration, not the other way around, so this probably won't be "fixed" on the Viper side. Most of the issues are around handling flags. Internally, Cobra allows defining multiple FlagSets whereas usually there is only one Viper instance. This is a problem, when multiple FlagSets define the same flags. Another common problem is Cobra's Some workarounds for :
Feel free to share more snippets below! |
Beta Was this translation helpful? Give feedback.
Historically both Viper and Cobra originate from Hugo, a static page generator, but the individual libraries don't have any tight integration between them. This might change in the future though: with Viper 2, consumers (like Cobra) will have much more control over how they integrate with Viper.
Nevertheless, it'll still be Cobra's job to handle the integration, not the other way around, so this probably won't be "fixed" on the Viper side.
Most of the issues are around handling flags. Internally, Cobra allows defining multiple FlagSets whereas usually there is only one Viper instance. This is a problem, when multiple FlagSets define the same flags.
Another common problem is Cobra's
Required
…