spf13 / pflag

Drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
BSD 3-Clause "New" or "Revised" License
2.43k stars 348 forks source link

Expose value pointer from Pflags created with VarP methods #319

Open domano opened 3 years ago

domano commented 3 years ago

Hi, this is a feature request mainly to make cobra & viper integration easier.

If the VarP-methods for flags are used then there is a pointer value for a variable which will be filled with the flags' value.

Example: image

Currently the pointer is just used to fill the variable.

It would be nice if the pointer was stored somewhere and could be retrieved.

This would allow for easy setting of all variables pointed to when using cobras' VisitAll function: cmd.Flags().VisitAll(func(f *pflag.Flag) {}).

Right now one has to manually set all variables by fetching them via viper and setting them, something like this: myVar := v.Get(f.Name).