Update root command setup to respect home flag (#34)
All checks were successful
Integration Tests / test-integration (push) Successful in 2m33s
E2E Tests / test-e2e (push) Successful in 3m48s
Lint / Run golangci-lint (push) Successful in 5m41s
Unit Tests / test-unit (push) Successful in 1m51s
SDK Tests / sdk_tests_nameservice_expiry (push) Successful in 7m31s
SDK Tests / sdk_tests (push) Successful in 7m53s
SDK Tests / sdk_tests_auctions (push) Successful in 13m48s

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.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr()) cmd.SetErr(cmd.ErrOrStderr())
clientCtx = clientCtx.WithCmdContext(cmd.Context()) clientCtx = clientCtx.WithCmdContext(cmd.Context()).WithViper(EnvPrefix)
clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags())
if err != nil { if err != nil {
return err return err
@ -96,10 +96,6 @@ func NewRootCmd() *cobra.Command {
return err return err
} }
if err := client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
return err
}
// overwrite the minimum gas price from the app configuration // overwrite the minimum gas price from the app configuration
srvCfg := serverconfig.DefaultConfig() srvCfg := serverconfig.DefaultConfig()
srvCfg.MinGasPrices = "0photon" srvCfg.MinGasPrices = "0photon"
@ -138,7 +134,9 @@ func ProvideClientContext(
WithLegacyAmino(legacyAmino). WithLegacyAmino(legacyAmino).
WithInput(os.Stdin). WithInput(os.Stdin).
WithAccountRetriever(types.AccountRetriever{}). 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 WithViper(EnvPrefix) // env variable prefix
// Read the config again to overwrite the default values with the values from the config file // Read the config again to overwrite the default values with the values from the config file