feat(client): backport autocli for node service (#23811)

Co-authored-by: zakir <80246097+zakir-code@users.noreply.github.com>
This commit is contained in:
Alex | Interchain Labs 2025-02-26 10:17:26 -05:00 committed by GitHub
parent da14035fcf
commit 9b83b2f7b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 57 additions and 1 deletions

View File

@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
### Features
* (client) [#21074](https://github.com/cosmos/cosmos-sdk/pull/21074) Add auto cli for node service
### Bug Fixes
* (query) [87d3a43](https://github.com/cosmos/cosmos-sdk/commit/87d3a432af95f4cf96aa02351ed5fcc51cca6e7b) Fix collection filtered pagination.

View File

@ -0,0 +1,43 @@
package node
import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
nodev1beta1 "cosmossdk.io/api/cosmos/base/node/v1beta1"
)
var ServiceAutoCLIDescriptor = &autocliv1.ServiceCommandDescriptor{
Service: nodev1beta1.Service_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Config",
Use: "config",
Short: "Query the current node config",
},
{
RpcMethod: "Status",
Use: "status",
Short: "Query the current node status",
},
},
}
// NewNodeCommands is a fake `appmodule.Module` to be considered as a module
// and be added in AutoCLI.
func NewNodeCommands() *nodeModule {
return &nodeModule{}
}
type nodeModule struct{}
func (m nodeModule) IsOnePerModuleType() {}
func (m nodeModule) IsAppModule() {}
func (m nodeModule) Name() string {
return "node"
}
func (m nodeModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: ServiceAutoCLIDescriptor,
}
}

View File

@ -13,6 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/server"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
@ -25,7 +26,6 @@ import (
// main function.
func NewRootCmd() *cobra.Command {
// we "pre"-instantiate the application for getting the injected/configured encoding configuration
// note, this is not necessary when using app wiring, as depinject can be directly used (see root_v2.go)
tempApp := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome))
encodingConfig := params.EncodingConfig{
InterfaceRegistry: tempApp.InterfaceRegistry(),
@ -101,6 +101,9 @@ func NewRootCmd() *cobra.Command {
autoCliOpts := tempApp.AutoCliOpts()
autoCliOpts.ClientCtx = initClientCtx
nodeCmds := nodeservice.NewNodeCommands()
autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions()
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}

View File

@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
@ -14,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/server"
@ -80,6 +82,10 @@ func NewRootCmd() *cobra.Command {
initRootCmd(rootCmd, clientCtx.TxConfig, moduleBasicManager)
nodeCmds := nodeservice.NewNodeCommands()
autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions)
autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions()
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}