Documentation
¶
Overview ¶
Package protoflag is a tiny Go library that can turn any Protocol Buffer message into a set of command‑line flags.
Index ¶
- Constants
- func JSONName(path []protoreflect.FieldDescriptor) string
- func Name(path []protoreflect.FieldDescriptor) string
- func ShouldDescend(r FilterResult) bool
- func ShouldInclude(r FilterResult) bool
- func TextName(path []protoreflect.FieldDescriptor) string
- type FilterFunc
- type FilterResult
- type Value
- func (val *Value) EnumDescriptor() protoreflect.EnumDescriptor
- func (val *Value) Get() any
- func (val *Value) GetValue() protoreflect.Value
- func (val *Value) IsBoolFlag() bool
- func (val *Value) IsList() bool
- func (val *Value) IsMap() bool
- func (val *Value) Kind() protoreflect.Kind
- func (val *Value) MessageDescriptor() protoreflect.MessageDescriptor
- func (val *Value) MessageType() protoreflect.MessageType
- func (val *Value) Path() []protoreflect.FieldDescriptor
- func (val *Value) Set(to string) error
- func (val *Value) SetDecoder(fn func([]byte, protoreflect.Message, protoreflect.FieldDescriptor) error)
- func (val *Value) SetEncoder(fn func(protoreflect.Value) ([]byte, error))
- func (val *Value) String() string
- func (val *Value) Type() string
Constants ¶
const ( IncludeAndDescend = jsonflag.IncludeAndDescend // indicates that the given flag value should be included, and that recursive value retrieval should descend into sub-values IncludeNoDescend = jsonflag.IncludeNoDescend // indicates that the given flag value should be included, but that recursive value retrieval should NOT descend into sub-values SkipAndDescend = jsonflag.SkipAndDescend // indicates that the given flag value should be skipped, but that recursive value retrieval should descend into sub-values SkipNoDescend = jsonflag.SkipNoDescend // indicates that the given flag value should be skipped, and that recursive value retrieval should NOT descend into sub-values )
Variables ¶
This section is empty.
Functions ¶
func JSONName ¶
func JSONName(path []protoreflect.FieldDescriptor) string
JSONName creates a new flag name by joining all JSON names of fields along the provided path.
func Name ¶
func Name(path []protoreflect.FieldDescriptor) string
Name creates a new flag name by joining all names of fields along the provided path.
func ShouldDescend ¶
func ShouldDescend(r FilterResult) bool
ShouldDescend informs if the provided filter result indicates that the further recursive values finding should descend into sub-values.
func ShouldInclude ¶
func ShouldInclude(r FilterResult) bool
ShouldInclude informs if the provided filter result indicates that the given flag value should be included.
func TextName ¶
func TextName(path []protoreflect.FieldDescriptor) string
TextName creates a new flag name by joining all text names of fields along the provided path.
Types ¶
type FilterFunc ¶
type FilterFunc func(*Value) FilterResult
FilterFunc is a function that can be used to decide if a flag value should be included in recursive results as well as if flag values finding should descend into the sub-values.
type FilterResult ¶
type FilterResult = jsonflag.FilterResult
FilterResult is a bit field holding filtering decision.
func Filter ¶
func Filter(val *Value, filters ...FilterFunc) (r FilterResult)
Filter applies all filter function to the provided flag value and returns filtering decision.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is a value of a flag for some proto message or its field.
func New ¶
New returns new flag value for the provided proto message. It returns nil if the message cannot be used as flag value.
func Recursive ¶
func Recursive(base proto.Message, filters ...FilterFunc) []*Value
Recursive returns set of flag values for the provided proto message and all fields within, recursively, according to the provided filters. Function silently skips all the fields that cannot be used as flag values.
func (*Value) EnumDescriptor ¶
func (val *Value) EnumDescriptor() protoreflect.EnumDescriptor
EnumDescriptor returns enum descriptor of the enum associated with the provided value, or nil, if the value is not associated with an enum.
func (*Value) Get ¶
Get returns current underlying value of the provided value. The actual data returned depends on underlying type associated with the value:
- for scalars function returns their associated Go values directly,
- for enums function returns enum number (protoreflect.EnumNumber type)
- for messages function returns their values directly,
- for lists of scalars function returns slices of their associated Go values,
- for lists of enums function returns slices of enum numbers (protoreflect.EnumNumber type),
- for lists of messages function returns slices of proto.Messages,
- for maps of scalars function returns maps of their associated Go values,
- for maps of enums function returns maps of enum numbers (protoreflect.EnumNumber type),
- for maps of messages function returns maps of proto.Messages.
func (*Value) GetValue ¶
func (val *Value) GetValue() protoreflect.Value
GetValue returns current underlying protoreflect value of the provided value.
func (*Value) IsBoolFlag ¶
IsBoolFlag informs if the underlying value is bool-like (bool field or repeated bool field).
func (*Value) IsList ¶
IsList returns true of the type associated with the provided value is a list.
func (*Value) Kind ¶
func (val *Value) Kind() protoreflect.Kind
Kind returns kind of the type described by the value.
func (*Value) MessageDescriptor ¶
func (val *Value) MessageDescriptor() protoreflect.MessageDescriptor
MessageDescriptor returns message descriptor of the message associated with the provided value, or nil, if the value is not associated with a message.
func (*Value) MessageType ¶
func (val *Value) MessageType() protoreflect.MessageType
MessageType returns message type of the message associated with the provided value, or nil, if the value is not associated with a message.
func (*Value) Path ¶
func (val *Value) Path() []protoreflect.FieldDescriptor
Path returns list of field descriptor from the base message up to the field associated with the provided value. It returns empty list if the value is associated with the base message itself.
func (*Value) SetDecoder ¶
func (val *Value) SetDecoder(fn func([]byte, protoreflect.Message, protoreflect.FieldDescriptor) error)
SetDecoder allows setting custom decoder of the underlying value.
func (*Value) SetEncoder ¶
func (val *Value) SetEncoder(fn func(protoreflect.Value) ([]byte, error))
SetEncoder allows setting custom encoder of the underlying value.