fix: Rework InterceptConfigsPreRunHandler to make sure configuration … (#7501)

* fix: Rework InterceptConfigsPreRunHandler to make sure configuration is pulled from all Viper sources

* docs: Add configuration documentation in a new file
This commit is contained in:
Eric
2020-10-16 13:56:10 +00:00
committed by GitHub
parent 6e569e1255
commit 8384a5a180
3 changed files with 511 additions and 17 deletions
+27
View File
@@ -0,0 +1,27 @@
/*
The commands from the SDK are defined with `cobra` and configured with the
`viper` package.
This takes place in the `InterceptConfigsPreRunHandler` function.
Since the `viper` package is used for configuration the precedence is dictated
by that package. That is
1. Command line switches
2. Environment variables
3. Files from configuration values
4. Default values
The global configuration instance exposed by the `viper` package is not
used by Cosmos SDK in this function. A new instance of `viper.Viper` is created
and the following is performed. The environmental variable prefix is set
to the current program name. Environmental variables consider the underscore
to be equivalent to the `.` or `-` character. This means that an configuration
value called `rpc.laddr` would be read from an environmental variable called
`MYTOOL_RPC_LADDR` if the current program name is `mytool`.
Running the `InterceptConfigsPreRunHandler` also reads `app.toml`
and `config.toml` from the home directory under the `config` directory.
If `config.toml` or `app.toml` do not exist then those files are created
and populated with default values.
*/
package server