From 6b0e8c19cd4702bfdfd964bee25e14933fb2dc2a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 25 Mar 2024 15:17:07 +0100 Subject: [PATCH] better api --- docs/build/building-apps/05-app-testnet.md | 4 ++-- server/types/app.go | 4 ---- server/util.go | 17 +++++++++-------- simapp/simd/cmd/commands.go | 6 +----- simapp/simd/cmd/root.go | 2 +- simapp/simd/cmd/root_di.go | 2 +- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/docs/build/building-apps/05-app-testnet.md b/docs/build/building-apps/05-app-testnet.md index c799236872d73..01c1267142d11 100644 --- a/docs/build/building-apps/05-app-testnet.md +++ b/docs/build/building-apps/05-app-testnet.md @@ -195,8 +195,8 @@ Before we can run the testnet we must plug everything together. in `root.go`, in the `initRootCmd` function we add: ```diff - server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, createMerlinAppAndExport, addModuleInitFlags) - ++ server.AddTestnetCreatorCommand(rootCmd, simapp.DefaultNodeHome, newTestnetApp, addModuleInitFlags) +server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, createMerlinAppAndExport) ++server.AddTestnetCreatorCommand(rootCmd, simapp.DefaultNodeHome, newTestnetApp) ``` Next we will add a newTestnetApp helper function: diff --git a/server/types/app.go b/server/types/app.go index 8d73f69e13f1b..8a0944afca050 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -8,7 +8,6 @@ import ( cmttypes "github.com/cometbft/cometbft/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/grpc" - "github.com/spf13/cobra" "cosmossdk.io/log" "cosmossdk.io/store/snapshots" @@ -68,9 +67,6 @@ type ( // application using various configurations. AppCreator[T Application] func(log.Logger, dbm.DB, io.Writer, AppOptions) T - // ModuleInitFlags takes a start command and adds modules specific init flags. - ModuleInitFlags func(startCmd *cobra.Command) - // ExportedApp represents an exported app state, along with // validators, consensus params and latest app height. ExportedApp struct { diff --git a/server/util.go b/server/util.go index de48b0bad3434..4262c288afd53 100644 --- a/server/util.go +++ b/server/util.go @@ -324,7 +324,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo } // AddCommands add server commands -func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], addStartFlags types.ModuleInitFlags) { +func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], opts StartCmdOptions[T]) { cometCmd := &cobra.Command{ Use: "comet", Aliases: []string{"cometbft", "tendermint"}, @@ -341,11 +341,7 @@ func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.A BootstrapStateCmd(appCreator), ) - startCmd := StartCmd(appCreator) - if addStartFlags != nil { - addStartFlags(startCmd) - } - + startCmd := StartCmdWithOptions(appCreator, opts) rootCmd.AddCommand( startCmd, cometCmd, @@ -354,10 +350,15 @@ func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.A ) } +// AddCommandsWithStartCmdOptions adds server commands with the provided StartCmdOptions. +// Deprecated: Use AddCommands directly instead. +func AddCommandsWithStartCmdOptions[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], opts StartCmdOptions[T]) { + AddCommands(rootCmd, appCreator, opts) +} + // AddTestnetCreatorCommand allows chains to create a testnet from the state existing in their node's data directory. -func AddTestnetCreatorCommand[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], addStartFlags types.ModuleInitFlags) { +func AddTestnetCreatorCommand[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T]) { testnetCreateCmd := InPlaceTestnetCreator(appCreator) - addStartFlags(testnetCreateCmd) rootCmd.AddCommand(testnetCreateCmd) } diff --git a/simapp/simd/cmd/commands.go b/simapp/simd/cmd/commands.go index 40de6d208cf87..d28de5c0eaf27 100644 --- a/simapp/simd/cmd/commands.go +++ b/simapp/simd/cmd/commands.go @@ -23,8 +23,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/pruning" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/client/snapshot" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,8 +33,6 @@ import ( func initRootCmd( rootCmd *cobra.Command, txConfig client.TxConfig, - interfaceRegistry codectypes.InterfaceRegistry, - appCodec codec.Codec, moduleManager *module.Manager, ) { cfg := sdk.GetConfig() @@ -51,7 +47,7 @@ func initRootCmd( snapshot.Cmd(newApp), ) - server.AddCommands(rootCmd, newApp, func(startCmd *cobra.Command) {}) + server.AddCommands(rootCmd, newApp, server.StartCmdOptions[servertypes.Application]{}) // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index e2c0fec476043..2b66d8cbe5775 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -110,7 +110,7 @@ func NewRootCmd() *cobra.Command { }, } - initRootCmd(rootCmd, encodingConfig.TxConfig, encodingConfig.InterfaceRegistry, encodingConfig.Codec, tempApp.ModuleManager) + initRootCmd(rootCmd, encodingConfig.TxConfig, tempApp.ModuleManager) // autocli opts customClientTemplate, customClientConfig := initClientConfig() diff --git a/simapp/simd/cmd/root_di.go b/simapp/simd/cmd/root_di.go index 8f5a535a62cfc..cfc8407edc119 100644 --- a/simapp/simd/cmd/root_di.go +++ b/simapp/simd/cmd/root_di.go @@ -87,7 +87,7 @@ func NewRootCmd() *cobra.Command { }, } - initRootCmd(rootCmd, clientCtx.TxConfig, clientCtx.InterfaceRegistry, clientCtx.Codec, moduleManager) + initRootCmd(rootCmd, clientCtx.TxConfig, moduleManager) if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { panic(err)