* WIP on auto-generating CLi * WIP * WIP * WIP * add pagination.go * handle more flag types * WIP on refactoring * WIP * working tests * add docs * echo all flags * add repeated tests * remove comment * fix compositeListValue issue Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package flag
|
|
|
|
import (
|
|
"google.golang.org/protobuf/reflect/protodesc"
|
|
"google.golang.org/protobuf/reflect/protoreflect"
|
|
"google.golang.org/protobuf/reflect/protoregistry"
|
|
)
|
|
|
|
// Builder manages options for building pflag flags for protobuf messages.
|
|
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
|
|
|
|
messageFlagTypes map[protoreflect.FullName]Type
|
|
scalarFlagTypes map[string]Type
|
|
}
|
|
|
|
func (b *Builder) init() {
|
|
if b.messageFlagTypes == nil {
|
|
b.messageFlagTypes = map[protoreflect.FullName]Type{}
|
|
b.messageFlagTypes["google.protobuf.Timestamp"] = timestampType{}
|
|
b.messageFlagTypes["google.protobuf.Duration"] = durationType{}
|
|
}
|
|
|
|
if b.scalarFlagTypes == nil {
|
|
b.scalarFlagTypes = map[string]Type{}
|
|
b.scalarFlagTypes["cosmos.AddressString"] = addressStringType{}
|
|
}
|
|
}
|
|
|
|
func (b *Builder) DefineMessageFlagType(messageName protoreflect.FullName, flagType Type) {
|
|
b.init()
|
|
b.messageFlagTypes[messageName] = flagType
|
|
}
|
|
|
|
func (b *Builder) DefineScalarFlagType(scalarName string, flagType Type) {
|
|
b.init()
|
|
b.scalarFlagTypes[scalarName] = flagType
|
|
}
|