mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: CLI use multiselect for list(string) (#6631)
* feat: CLI use multiselect for list(string) * fix * select ui tests * cli test * Fix * Fix
This commit is contained in:
+23
-1
@@ -1,6 +1,7 @@
|
||||
package cliui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -69,7 +70,28 @@ func RichParameter(cmd *cobra.Command, templateVersionParameter codersdk.Templat
|
||||
|
||||
var err error
|
||||
var value string
|
||||
if len(templateVersionParameter.Options) > 0 {
|
||||
if templateVersionParameter.Type == "list(string)" {
|
||||
// Move the cursor up a single line for nicer display!
|
||||
_, _ = fmt.Fprint(cmd.OutOrStdout(), "\033[1A")
|
||||
|
||||
var options []string
|
||||
err = json.Unmarshal([]byte(templateVersionParameter.DefaultValue), &options)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
values, err := MultiSelect(cmd, options)
|
||||
if err == nil {
|
||||
v, err := json.Marshal(&values)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintln(cmd.OutOrStdout())
|
||||
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+Styles.Prompt.String()+Styles.Field.Render(strings.Join(values, ", ")))
|
||||
value = string(v)
|
||||
}
|
||||
} else if len(templateVersionParameter.Options) > 0 {
|
||||
// Move the cursor up a single line for nicer display!
|
||||
_, _ = fmt.Fprint(cmd.OutOrStdout(), "\033[1A")
|
||||
var richParameterOption *codersdk.TemplateVersionParameterOption
|
||||
|
||||
Reference in New Issue
Block a user