Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c938cd

Browse files
authored
chore(cli): exp prompt-example: add option to multi-select (#15496)
Adds a `--things` flag to our `multi-select` example prompt command.```go run ./cmd/coder exp prompt-example multi-select --things=Code,Bike,Potato=mashed"Code, Bike, Potato=mashed" are nice choices.```
1 parentf2fe379 commit1c938cd

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

‎cli/prompts.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,26 @@ func (RootCmd) promptExample() *serpent.Command {
2222
}
2323
}
2424

25-
varuseSearchbool
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+
useSearchbool
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+
multiSelectErrorerror
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+
)
3345
cmd:=&serpent.Command{
3446
Use:"prompt-example",
3547
Short:"Example of various prompt types used within coder cli.",
@@ -140,16 +152,18 @@ func (RootCmd) promptExample() *serpent.Command {
140152
returnerr
141153
}),
142154
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-
returnerr
152-
}),
155+
iflen(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+
returnmultiSelectError
166+
},useThingsOption),
153167
promptCmd("rich-parameter",func(inv*serpent.Invocation)error {
154168
value,err:=cliui.RichSelect(inv, cliui.RichSelectOptions{
155169
Options: []codersdk.TemplateVersionParameterOption{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp