autocli

package
v2.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2023 License: Apache-2.0 Imports: 32 Imported by: 83

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppOptions

type AppOptions struct {
	depinject.In

	// Modules are the AppModule implementations for the modules in the app.
	Modules map[string]appmodule.AppModule

	// ModuleOptions are autocli options to be used for modules instead of what
	// is specified on the module's AppModule implementation. This allows an
	// app to override module options if they are either not provided by a
	// module or need to be improved.
	ModuleOptions map[string]*autocliv1.ModuleOptions `optional:"true"`

	// AddressCodec is the address codec to use for the app.
	AddressCodec          address.Codec
	ValidatorAddressCodec runtime.ValidatorAddressCodec
	ConsensusAddressCodec runtime.ConsensusAddressCodec

	// Keyring is the keyring to use for client/v2.
	Keyring keyring.Keyring `optional:"true"`

	// ClientCtx contains the necessary information needed to execute the commands.
	ClientCtx client.Context

	// TxConfigOptions are the transactions config options.
	TxConfigOpts tx.ConfigOptions
}

AppOptions are autocli options for an app. These options can be built via depinject based on an app config. Ex: Ex:

var autoCliOpts autocli.AppOptions
err := depinject.Inject(appConfig, &encodingConfig.InterfaceRegistry, &autoCliOpts)

If depinject isn't used, options can be provided manually or extracted from modules and the address codec can be provided by the auth keeper. One method for extracting autocli options is via the github.com/cosmos/cosmos-sdk/runtime/services.ExtractAutoCLIOptions function.

func (AppOptions) EnhanceRootCommand

func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error

EnhanceRootCommand enhances the provided root command with autocli AppOptions, only adding missing commands and doesn't override commands already in the root command. This allows for the graceful integration of autocli with existing app CLI commands where autocli simply automatically adds things that weren't manually provided. It does take into account custom commands provided by modules with the HasCustomQueryCommand or HasCustomTxCommand extension interface. Example Usage:

var autoCliOpts autocli.AppOptions
err := depinject.Inject(appConfig, &autoCliOpts)
if err != nil {
	panic(err)
}
rootCmd := initRootCmd()
err = autoCliOpts.EnhanceRootCommand(rootCmd)

func (AppOptions) EnhanceRootCommandWithBuilder

func (appOptions AppOptions) EnhanceRootCommandWithBuilder(rootCmd *cobra.Command, builder *Builder) error

type Builder

type Builder struct {
	// flag.Builder embeds the flag builder and its options.
	flag.Builder

	// GetClientConn specifies how CLI commands will resolve a grpc.ClientConnInterface
	// from a given context.
	GetClientConn func(*cobra.Command) (grpc.ClientConnInterface, error)

	// ClientCtx contains the necessary information needed to execute the commands.
	ClientCtx client.Context

	// TxConfigOptions is required to support sign mode textual
	TxConfigOpts authtx.ConfigOptions

	// AddQueryConnFlags and AddTxConnFlags are functions that add flags to query and transaction commands
	AddQueryConnFlags func(*cobra.Command)
	AddTxConnFlags    func(*cobra.Command)
}

Builder manages options for building CLI commands.

func (*Builder) AddMsgServiceCommands

func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autocliv1.ServiceCommandDescriptor) error

AddMsgServiceCommands adds a sub-command to the provided command for each method in the specified service and returns the command. This can be used in order to add auto-generated commands to an existing command.

func (*Builder) AddQueryServiceCommands

func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *autocliv1.ServiceCommandDescriptor) error

AddQueryServiceCommands adds a sub-command to the provided command for each method in the specified service and returns the command. This can be used in order to add auto-generated commands to an existing command.

func (*Builder) BuildMsgCommand

func (b *Builder) BuildMsgCommand(appOptions AppOptions, customCmds map[string]*cobra.Command) (*cobra.Command, error)

BuildMsgCommand builds the msg commands for all the provided modules. If a custom command is provided for a module, this is used instead of any automatically generated CLI commands. This allows apps to a fully dynamic client with a more customized experience if a binary with custom commands is downloaded.

func (*Builder) BuildMsgMethodCommand

func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error)

BuildMsgMethodCommand returns a command that outputs the JSON representation of the message.

func (*Builder) BuildQueryCommand

func (b *Builder) BuildQueryCommand(appOptions AppOptions, customCmds map[string]*cobra.Command) (*cobra.Command, error)

BuildQueryCommand builds the query commands for all the provided modules. If a custom command is provided for a module, this is used instead of any automatically generated CLI commands. This allows apps to a fully dynamic client with a more customized experience if a binary with custom commands is downloaded.

func (*Builder) BuildQueryMethodCommand

func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error)

BuildQueryMethodCommand creates a gRPC query command for the given service method. This can be used to auto-generate just a single command for a single service rpc method.

func (*Builder) ValidateAndComplete

func (b *Builder) ValidateAndComplete() error

ValidateAndComplete the builder fields. It returns an error if any of the required fields are missing. If the Logger is nil, it will be set to a nop logger. If the keyring is nil, it will be set to a no keyring.

type HasAutoCLIConfig

type HasAutoCLIConfig interface {
	appmodule.AppModule

	// AutoCLIOptions are the autocli module options for this module.
	AutoCLIOptions() *autocliv1.ModuleOptions
}

HasAutoCLIConfig is an AppModule extension interface for declaring autocli module options.

type HasCustomQueryCommand

type HasCustomQueryCommand interface {
	appmodule.AppModule

	// GetQueryCmd returns a custom cobra query command for this module.
	GetQueryCmd() *cobra.Command
}

HasCustomQueryCommand is an AppModule extension interface for declaring a custom query command.

type HasCustomTxCommand

type HasCustomTxCommand interface {
	appmodule.AppModule

	// GetTxCmd returns a custom cobra tx command for this module.
	GetTxCmd() *cobra.Command
}

HasCustomTxCommand is an AppModule extension interface for declaring a custom tx command.

Directories

Path Synopsis
Package flag defines functionality for automatically managing command line flags as well positional arguments that are based on protobuf message fields.
Package flag defines functionality for automatically managing command line flags as well positional arguments that are based on protobuf message fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL