Skip to content

Commit 7d69335

Browse files
committed
Add edit org role
1 parent de8149f commit 7d69335

File tree

7 files changed

+365
-22
lines changed

7 files changed

+365
-22
lines changed

cli/cliui/parameter.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ func RichParameter(inv *serpent.Invocation, templateVersionParameter codersdk.Te
4343
return "", err
4444
}
4545

46-
values, err := MultiSelect(inv, options)
46+
values, err := MultiSelect(inv, MultiSelectOptions{
47+
Options: options,
48+
Defaults: options,
49+
})
4750
if err == nil {
4851
v, err := json.Marshal(&values)
4952
if err != nil {

cli/cliui/select.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type SelectOptions struct {
5656
Options []string
5757
// Default will be highlighted first if it's a valid option.
5858
Default string
59+
Message string
5960
Size int
6061
HideSearch bool
6162
}
@@ -122,6 +123,7 @@ func Select(inv *serpent.Invocation, opts SelectOptions) (string, error) {
122123
Options: opts.Options,
123124
Default: defaultOption,
124125
PageSize: opts.Size,
126+
Message: opts.Message,
125127
}, &value, survey.WithIcons(func(is *survey.IconSet) {
126128
is.Help.Text = "Type to search"
127129
if opts.HideSearch {
@@ -138,15 +140,22 @@ func Select(inv *serpent.Invocation, opts SelectOptions) (string, error) {
138140
return value, err
139141
}
140142

141-
func MultiSelect(inv *serpent.Invocation, items []string) ([]string, error) {
143+
type MultiSelectOptions struct {
144+
Message string
145+
Options []string
146+
Defaults []string
147+
}
148+
149+
func MultiSelect(inv *serpent.Invocation, opts MultiSelectOptions) ([]string, error) {
142150
// Similar hack is applied to Select()
143151
if flag.Lookup("test.v") != nil {
144-
return items, nil
152+
return opts.Defaults, nil
145153
}
146154

147155
prompt := &survey.MultiSelect{
148-
Options: items,
149-
Default: items,
156+
Options: opts.Options,
157+
Default: opts.Defaults,
158+
Message: opts.Message,
150159
}
151160

152161
var values []string

cli/cliui/select_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ func newMultiSelect(ptty *ptytest.PTY, items []string) ([]string, error) {
107107
var values []string
108108
cmd := &serpent.Command{
109109
Handler: func(inv *serpent.Invocation) error {
110-
selectedItems, err := cliui.MultiSelect(inv, items)
110+
selectedItems, err := cliui.MultiSelect(inv, cliui.MultiSelectOptions{
111+
Options: items,
112+
Defaults: items,
113+
})
111114
if err == nil {
112115
values = selectedItems
113116
}

0 commit comments

Comments
 (0)