Skip to content

Commit

Permalink
add prefix for enum type
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh committed Jan 11, 2022
1 parent fbe7341 commit 0fc2236
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions fill/proto/interactive_filler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package prompt

import (
"fmt"
"io"
"os"

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0fc2236

Please sign in to comment.