Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add prefix for enum type #481

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the prompt has an unnecessary character :, it's better to trim it like ? choice (TYPE_ENUM) =>.
This can be pass a template through Templates.Label of promptui.Select (the implementation of the prompt).

FYI: the default template label is maybe here.

image

Copy link
Contributor Author

@xwjdsh xwjdsh Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the diff. Wait a minute, maybe it's better to pass the template.

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