Documentation ¶
Overview ¶
Package flag defines functionality for automatically managing command line flags as well positional arguments that are based on protobuf message fields.
Index ¶
- Constants
- func GetScalarType(field protoreflect.FieldDescriptor) (string, bool)
- func GetSignerFieldName(descriptor protoreflect.MessageDescriptor) string
- type Builder
- func (b *Builder) AddMessageFlags(ctx *context.Context, flagSet *pflag.FlagSet, ...) (*MessageBinder, error)
- func (b *Builder) DefineMessageFlagType(messageName protoreflect.FullName, flagType Type)
- func (b *Builder) DefineScalarFlagType(scalarName string, flagType Type)
- func (b *Builder) ValidateAndComplete() error
- type HasValue
- type MessageBinder
- type SignerInfo
- type Type
- type Value
Constants ¶
const ( AddressStringScalarType = "cosmos.AddressString" ValidatorAddressStringScalarType = "cosmos.ValidatorAddressString" ConsensusAddressStringScalarType = "cosmos.ConsensusAddressString" PubkeyScalarType = "cosmos.Pubkey" )
Variables ¶
This section is empty.
Functions ¶
func GetScalarType ¶
func GetScalarType(field protoreflect.FieldDescriptor) (string, bool)
GetScalarType gets scalar type of a field.
func GetSignerFieldName ¶
func GetSignerFieldName(descriptor protoreflect.MessageDescriptor) string
GetSignerFieldName gets signer field name of a message. AutoCLI supports only one signer field per message.
Types ¶
type Builder ¶
type Builder struct { // TypeResolver specifies how protobuf types will be resolved. If it is // nil protoregistry.GlobalTypes will be used. TypeResolver interface { protoregistry.MessageTypeResolver protoregistry.ExtensionTypeResolver } // FileResolver specifies how protobuf file descriptors will be resolved. If it is // nil protoregistry.GlobalFiles will be used. FileResolver interface { protodesc.Resolver RangeFiles(func(protoreflect.FileDescriptor) bool) } // Address Codecs are the address codecs to use for client/v2. AddressCodec address.Codec ValidatorAddressCodec runtime.ValidatorAddressCodec ConsensusAddressCodec runtime.ConsensusAddressCodec // contains filtered or unexported fields }
Builder manages options for building pflag flags for protobuf messages.
func (*Builder) AddMessageFlags ¶
func (b *Builder) AddMessageFlags(ctx *context.Context, flagSet *pflag.FlagSet, messageType protoreflect.MessageType, commandOptions *autocliv1.RpcCommandOptions) (*MessageBinder, error)
AddMessageFlags adds flags for each field in the message to the flag set.
func (*Builder) DefineMessageFlagType ¶
func (b *Builder) DefineMessageFlagType(messageName protoreflect.FullName, flagType Type)
DefineMessageFlagType allows to extend custom protobuf message type handling for flags (and positional arguments).
func (*Builder) DefineScalarFlagType ¶
DefineScalarFlagType allows to extend custom scalar type handling for flags (and positional arguments).
type HasValue ¶
type HasValue interface { // Get gets the value of the protobuf value reference and returns that value // or an error. For composite protoreflect.Value types such as messages, // lists and maps, a mutable reference to the value of field obtained with // protoreflect.Message.NewField should be passed as the newFieldValue parameter. Get(newFieldValue protoreflect.Value) (protoreflect.Value, error) }
HasValue wraps a reference to a protobuf value.
type MessageBinder ¶
type MessageBinder struct { CobraArgs cobra.PositionalArgs SignerInfo SignerInfo // contains filtered or unexported fields }
MessageBinder binds multiple flags in a flag set to a protobuf message.
func (MessageBinder) Bind ¶
func (m MessageBinder) Bind(msg protoreflect.Message, positionalArgs []string) error
Bind binds the flag values to an existing protobuf message.
func (MessageBinder) BuildMessage ¶
func (m MessageBinder) BuildMessage(positionalArgs []string) (protoreflect.Message, error)
BuildMessage builds and returns a new message for the bound flags.
func (MessageBinder) Get ¶
func (m MessageBinder) Get(protoreflect.Value) (protoreflect.Value, error)
Get calls BuildMessage and wraps the result in a protoreflect.Value.
type SignerInfo ¶
type SignerInfo struct { PositionalArgIndex int IsFlag bool FieldName string FlagName string // flag name (always set if IsFlag is true) }
SignerInfo contains information about the signer field. That field is special because it needs to be known for signing. This struct keeps track of the field name and whether it is a flag. IsFlag and PositionalArgIndex are mutually exclusive.