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:
Marcin Tojek
2023-03-16 17:17:48 +01:00
committed by GitHub
parent 95177ad0e5
commit 1f9ae15409
6 changed files with 199 additions and 6 deletions
+23 -1
View File
@@ -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