mirror of
https://github.com/spf13/viper
synced 2025-06-13 14:47:19 +00:00
Merge dc20f95f1f
into 260b8e9a3c
This commit is contained in:
commit
5d0706ed86
1 changed files with 10 additions and 0 deletions
10
README.md
10
README.md
|
@ -301,6 +301,16 @@ os.Setenv("SPF_ID", "13") // typically done outside of the app
|
||||||
id := Get("id") // 13
|
id := Get("id") // 13
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### When working with *required flags with Cobra+Viper*, you must set the flag values after binding to them. Otherwise Cobra won't be aware of the value from any source other tha the CLI itself.
|
||||||
|
|
||||||
|
```go
|
||||||
|
serverCmd.Flags().VisitAll(func(f *pflag.Flag) {
|
||||||
|
if viper.IsSet(f.Name) && viper.GetString(f.Name) != "" {
|
||||||
|
serverCmd.Flags().Set(f.Name, viper.GetString(f.Name))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### Working with Flags
|
### Working with Flags
|
||||||
|
|
||||||
Viper has the ability to bind to flags. Specifically, Viper supports `Pflags`
|
Viper has the ability to bind to flags. Specifically, Viper supports `Pflags`
|
||||||
|
|
Loading…
Add table
Reference in a new issue