@@ -22,14 +22,26 @@ func (RootCmd) promptExample() *serpent.Command {
22
22
}
23
23
}
24
24
25
- var useSearch bool
26
- useSearchOption := serpent.Option {
27
- Name : "search" ,
28
- Description : "Show the search." ,
29
- Required : false ,
30
- Flag : "search" ,
31
- Value : serpent .BoolOf (& useSearch ),
32
- }
25
+ var (
26
+ useSearch bool
27
+ useSearchOption = serpent.Option {
28
+ Name : "search" ,
29
+ Description : "Show the search." ,
30
+ Required : false ,
31
+ Flag : "search" ,
32
+ Value : serpent .BoolOf (& useSearch ),
33
+ }
34
+
35
+ multiSelectValues []string
36
+ multiSelectError error
37
+ useThingsOption = serpent.Option {
38
+ Name : "things" ,
39
+ Description : "Tell me what things you want." ,
40
+ Flag : "things" ,
41
+ Default : "" ,
42
+ Value : serpent .StringArrayOf (& multiSelectValues ),
43
+ }
44
+ )
33
45
cmd := & serpent.Command {
34
46
Use : "prompt-example" ,
35
47
Short : "Example of various prompt types used within coder cli." ,
@@ -140,16 +152,18 @@ func (RootCmd) promptExample() *serpent.Command {
140
152
return err
141
153
}),
142
154
promptCmd ("multi-select" , func (inv * serpent.Invocation ) error {
143
- values , err := cliui .MultiSelect (inv , cliui.MultiSelectOptions {
144
- Message : "Select some things:" ,
145
- Options : []string {
146
- "Code" , "Chair" , "Whale" , "Diamond" , "Carrot" ,
147
- },
148
- Defaults : []string {"Code" },
149
- })
150
- _ , _ = fmt .Fprintf (inv .Stdout , "%q are nice choices.\n " , strings .Join (values , ", " ))
151
- return err
152
- }),
155
+ if len (multiSelectValues ) == 0 {
156
+ multiSelectValues , multiSelectError = cliui .MultiSelect (inv , cliui.MultiSelectOptions {
157
+ Message : "Select some things:" ,
158
+ Options : []string {
159
+ "Code" , "Chair" , "Whale" , "Diamond" , "Carrot" ,
160
+ },
161
+ Defaults : []string {"Code" },
162
+ })
163
+ }
164
+ _ , _ = fmt .Fprintf (inv .Stdout , "%q are nice choices.\n " , strings .Join (multiSelectValues , ", " ))
165
+ return multiSelectError
166
+ }, useThingsOption ),
153
167
promptCmd ("rich-parameter" , func (inv * serpent.Invocation ) error {
154
168
value , err := cliui .RichSelect (inv , cliui.RichSelectOptions {
155
169
Options : []codersdk.TemplateVersionParameterOption {
0 commit comments