MCPcopy Index your code
hub / github.com/coder/coder / RichSelect

Function RichSelect

cli/cliui/select.go:70–101  ·  view source on GitHub ↗

RichSelect displays a list of user options including name and description.

(inv *serpent.Invocation, richOptions RichSelectOptions)

Source from the content-addressed store, hash-verified

68
69// RichSelect displays a list of user options including name and description.
70func RichSelect(inv *serpent.Invocation, richOptions RichSelectOptions) (*codersdk.TemplateVersionParameterOption, error) {
71 opts := make([]string, len(richOptions.Options))
72 var defaultOpt string
73 for i, option := range richOptions.Options {
74 line := option.Name
75 if len(option.Description) > 0 {
76 line += ": " + option.Description
77 }
78 opts[i] = line
79
80 if option.Value == richOptions.Default {
81 defaultOpt = line
82 }
83 }
84
85 selected, err := Select(inv, SelectOptions{
86 Options: opts,
87 Default: defaultOpt,
88 Size: richOptions.Size,
89 HideSearch: richOptions.HideSearch,
90 })
91 if err != nil {
92 return nil, err
93 }
94
95 for i, option := range opts {
96 if option == selected {
97 return &richOptions.Options[i], nil
98 }
99 }
100 return nil, xerrors.Errorf("unknown option selected: %s", selected)
101}
102
103// Select displays a list of user options.
104func Select(inv *serpent.Invocation, opts SelectOptions) (string, error) {

Callers 3

promptExampleMethod · 0.92
newRichSelectFunction · 0.92
RichParameterFunction · 0.85

Calls 2

SelectFunction · 0.85
ErrorfMethod · 0.45

Tested by 1

newRichSelectFunction · 0.74