flag

package
v2.0.0-...-095f669 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 protodesc.Resolver
	// 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)

func (*Builder) DefineMessageFlagType

func (b *Builder) DefineMessageFlagType(messageName protoreflect.FullName, flagType Type)

func (*Builder) DefineScalarFlagType

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

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

Jump to

Keyboard shortcuts

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