From 576569fe66b3e78a9113cbb77fbbf44173ce4da0 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 10 Jul 2024 12:32:49 +0000 Subject: [PATCH] Update root command setup to respect home flag (#34) Part of https://git.vdb.to/cerc-io/laconic2d/issues/32 and https://git.vdb.to/cerc-io/laconic2d/issues/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: https://git.vdb.to/cerc-io/laconic2d/pulls/34 Co-authored-by: Prathamesh Musale Co-committed-by: Prathamesh Musale --- cmd/laconicd/cmd/root.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cmd/laconicd/cmd/root.go b/cmd/laconicd/cmd/root.go index 303ef8f9..638f554f 100644 --- a/cmd/laconicd/cmd/root.go +++ b/cmd/laconicd/cmd/root.go @@ -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