Update root command setup to respect home flag (#34)

Part of cerc-io/laconic2d#32 and cerc-io/laconic2d#33

- Update context used in root command with Viper so that it recognizes the client config from home directory passed in CLI flags
- Avoid providing default home dir to depinject so that the home directory passed in CLI flags is used in txs
- Known issue: The client config from non-default home directory still doesn't seem to be getting used for some commands; in such cases, user has to pass the required flags explicitly

Reviewed-on: cerc-io/laconic2d#34
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
Prathamesh Musale 2024-07-10 12:32:49 +00:00 committed by ashwin
parent e63f51cacd
commit 576569fe66

View File

@ -68,7 +68,7 @@ func NewRootCmd() *cobra.Command {
cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr())
clientCtx = clientCtx.WithCmdContext(cmd.Context())
clientCtx = clientCtx.WithCmdContext(cmd.Context()).WithViper(EnvPrefix)
clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -96,10 +96,6 @@ func NewRootCmd() *cobra.Command {
return err
}
if err := client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
return err
}
// overwrite the minimum gas price from the app configuration
srvCfg := serverconfig.DefaultConfig()
srvCfg.MinGasPrices = "0photon"
@ -138,7 +134,9 @@ func ProvideClientContext(
WithLegacyAmino(legacyAmino).
WithInput(os.Stdin).
WithAccountRetriever(types.AccountRetriever{}).
WithHomeDir(app.DefaultNodeHome).
// Workaround: Avoid providing DefaultNodeHome to depinject as it is given precedence over the one passed using --home flag in some CLI commands
// TODO: Implement proper fix
// WithHomeDir(app.DefaultNodeHome).
WithViper(EnvPrefix) // env variable prefix
// Read the config again to overwrite the default values with the values from the config file