-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/node: automatically bind all flags with viper
We manually called viper.BindPFlag for every declared flag. Not only was this repetitive, it was also error prone. We can rely on viper's BindPFlags or BindFlagValues to bind many flags at once, without having to do each one of them separately. The BindPFlag calls used to add dots to group parts of the YAML config, such as `vochainLogLevel` becoming `vochain.LogLevel`. We can automate this with a little bit of glue code on BindFlagValues. There were also a few flags whose names deviated from the viper keys. This is not really a problem per se, but it is inconsistent, and it makes automatically binding between pflag and viper harder. The simplest path appears to be to rename the flags to agree with viper, keeping support for the old flag names via viper.SetNormalizeFunc. I sanity checked that this shouldn't be a breaking change by running `go run ./cmd/node --saveConfig` before and after the change with an empty configuration file and no env vars. Before the fixes above relating to the dots and inconsistent flag names, the YAML keys were very different. Now the YAML is the same as before. The flags should continue to work for the same reason: the YAML keys haven't changed, and the flag names are directly tied, so they shouldn't have changed in any breaking way either.
- Loading branch information
Showing
1 changed file
with
60 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters