From 0fc223679c8ac1ebbdb77fa5950949deb30af27f Mon Sep 17 00:00:00 2001 From: Wendell Sun Date: Wed, 24 Nov 2021 13:45:59 +0800 Subject: [PATCH] add prefix for enum type --- fill/proto/interactive_filler.go | 6 +++--- prompt/prompt.go | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fill/proto/interactive_filler.go b/fill/proto/interactive_filler.go index cec67758..0844972e 100644 --- a/fill/proto/interactive_filler.go +++ b/fill/proto/interactive_filler.go @@ -152,7 +152,7 @@ func (r *resolver) resolveField(f *desc.FieldDescriptor) error { ) return msgr.resolve() case descriptorpb.FieldDescriptorProto_TYPE_ENUM: - return r.resolveEnum(f.GetEnumType()) + return r.resolveEnum(r.makePrefix(f), f.GetEnumType()) case descriptorpb.FieldDescriptorProto_TYPE_DOUBLE: converter = func(v string) (interface{}, error) { return strconv.ParseFloat(v, 64) } @@ -254,13 +254,13 @@ func (r *resolver) resolveField(f *desc.FieldDescriptor) error { } } -func (r *resolver) resolveEnum(e *desc.EnumDescriptor) (int32, error) { +func (r *resolver) resolveEnum(prefix string, e *desc.EnumDescriptor) (int32, error) { choices := make([]string, 0, len(e.GetValues())) for _, v := range e.GetValues() { choices = append(choices, v.GetName()) } - choice, err := r.selectChoices(e.GetFullyQualifiedName(), choices) + choice, err := r.selectChoices(prefix, choices) if err != nil { return 0, err } diff --git a/prompt/prompt.go b/prompt/prompt.go index 72e517ab..2ed1ffa1 100644 --- a/prompt/prompt.go +++ b/prompt/prompt.go @@ -2,6 +2,7 @@ package prompt import ( + "fmt" "io" "os" @@ -87,7 +88,11 @@ func newPrompt(opts ...Option) Prompt { InputFunc: goprompt.Input, prefixColor: ColorInitial, SelectFunc: func(message string, options []string) (int, string, error) { - s := promptui.Select{Label: message, Items: options} + s := promptui.Select{ + Label: message, + Items: options, + Templates: &promptui.SelectTemplates{Label: fmt.Sprintf("%s {{.}}", promptui.IconInitial)}, + } return s.Run() }, commandHistory: opt.commandHistory,