flag

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: 37 Imported by: 1

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

View Source
const (
	AddressStringScalarType          = "cosmos.AddressString"
	ValidatorAddressStringScalarType = "cosmos.ValidatorAddressString"
	ConsensusAddressStringScalarType = "cosmos.ConsensusAddressString"
)

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)
	}

	// Keyring is the keyring to use for client/v2.
	Keyring keyring.Keyring

	// 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

func (b *Builder) DefineScalarFlagType(scalarName string, flagType Type)

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

Get calls BuildMessage and wraps the result in a protoreflect.Value.

type SignerInfo

type SignerInfo struct {
	PositionalArgIndex int
	IsFlag             bool
	FieldName          string
}

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.

type Type

type Type interface {
	// NewValue returns a new pflag.Value which must also implement either
	// SimpleValue or ListValue.
	NewValue(context.Context, *Builder) Value

	// DefaultValue is the default value for this type.
	DefaultValue() string
}

Type specifies a custom flag type.

type Value

type Value interface {
	pflag.Value
	HasValue
}

Value represents a single pflag.Value value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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