-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Hi,
I've been working on integrating Cobra with Viper using the Building a 12-Factor App with Viper Integration tutorial, but there are formatting issues in the code examples.
For example, there are raw markdown links in the imports:
package cmd
import (
"fmt"
"[github.com/spf13/cobra](https://github.com/spf13/cobra)"
"[github.com/spf13/viper](https://github.com/spf13/viper)"
)There's no indentation which makes it hard to read, and it looks like there are markdown code blocks inside the Go code:
var (
// Used for flags.
cfgFile string
```
rootCmd = &cobra.Command{
Use: "myapp",
Short: "A demo application for Cobra and Viper",
}
```
)Also, I think the documentation may be outdated. The Viper documentation states that:
The best practice is to initialize a Viper instance and pass that around when necessary.
Viper comes with a global instance (singleton) out of the box. Although it makes setting up configuration easy, using it is generally discouraged as it makes testing harder and can lead to unexpected behavior.
The global instance may be deprecated in the future. See spf13/viper#1855 for more details.
Yet the Cobra tutorial uses the singleton and PersistentPreRunE, which makes it harder to pass the Viper instance around without examples on how to handle it in a better way.
I don't know where the documentation source is located, but if someone can provide examples of the best way to handle Viper instances with Cobra, I'd be happy to submit a PR to update both the formatting and examples.