Skip to content

Commit

Permalink
refactor: wire autocli
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Oct 30, 2023
1 parent 4cb5230 commit b684604
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
7 changes: 2 additions & 5 deletions testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,8 @@ func (app *SimApp) AutoCliOpts() autocli.AppOptions {
}

return autocli.AppOptions{
Modules: modules,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules),
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
Modules: modules,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules),
}
}

Expand Down
31 changes: 30 additions & 1 deletion testing/simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/log"
confixcmd "cosmossdk.io/tools/confix/cmd"

Expand All @@ -21,6 +22,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/snapshot"
"github.com/cosmos/cosmos-sdk/codec"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -112,13 +115,39 @@ func NewRootCmd() *cobra.Command {

initRootCmd(rootCmd, encodingConfig, tempApp.BasicModuleManager)

if err := tempApp.AutoCliOpts().EnhanceRootCommand(rootCmd); err != nil {
autoCliOpts, err := enrichAutoCliOpts(tempApp.AutoCliOpts(), initClientCtx)
if err != nil {
panic(err)
}

if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}

return rootCmd
}

func enrichAutoCliOpts(autoCliOpts autocli.AppOptions, clientCtx client.Context) (autocli.AppOptions, error) {
autoCliOpts.AddressCodec = addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())
autoCliOpts.ValidatorAddressCodec = addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix())
autoCliOpts.ConsensusAddressCodec = addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix())

var err error
clientCtx, err = config.ReadFromClientConfig(clientCtx)
if err != nil {
return autocli.AppOptions{}, err
}

autoCliOpts.ClientCtx = clientCtx

Check failure on line 141 in testing/simapp/simd/cmd/root.go

View workflow job for this annotation

GitHub Actions / build (arm)

autoCliOpts.ClientCtx undefined (type autocli.AppOptions has no field or method ClientCtx)

Check failure on line 141 in testing/simapp/simd/cmd/root.go

View workflow job for this annotation

GitHub Actions / build (arm64)

autoCliOpts.ClientCtx undefined (type autocli.AppOptions has no field or method ClientCtx)

Check failure on line 141 in testing/simapp/simd/cmd/root.go

View workflow job for this annotation

GitHub Actions / build (amd64)

autoCliOpts.ClientCtx undefined (type autocli.AppOptions has no field or method ClientCtx)

Check failure on line 141 in testing/simapp/simd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint

autoCliOpts.ClientCtx undefined (type autocli.AppOptions has no field or method ClientCtx) (typecheck)

Check failure on line 141 in testing/simapp/simd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint

autoCliOpts.ClientCtx undefined (type autocli.AppOptions has no field or method ClientCtx)) (typecheck)

Check failure on line 141 in testing/simapp/simd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint

autoCliOpts.ClientCtx undefined (type autocli.AppOptions has no field or method ClientCtx)) (typecheck)

Check failure on line 141 in testing/simapp/simd/cmd/root.go

View workflow job for this annotation

GitHub Actions / tests (03)

autoCliOpts.ClientCtx undefined (type autocli.AppOptions has no field or method ClientCtx)

autoCliOpts.Keyring, err = keyring.NewAutoCLIKeyring(clientCtx.Keyring)
if err != nil {
return autocli.AppOptions{}, err
}

return autoCliOpts, nil
}

// initCometBFTConfig helps to override default CometBFT Config values.
// return cmtcfg.DefaultConfig if no custom configuration is required for the application.
func initCometBFTConfig() *cmtcfg.Config {
Expand Down

0 comments on commit b684604

Please sign in to comment.