(inv *serpent.Invocation, templateVersionParameter codersdk.TemplateVersionParameter, name, defaultValue string)
| 11 | ) |
| 12 | |
| 13 | func RichParameter(inv *serpent.Invocation, templateVersionParameter codersdk.TemplateVersionParameter, name, defaultValue string) (string, error) { |
| 14 | label := name |
| 15 | if templateVersionParameter.Ephemeral { |
| 16 | label += pretty.Sprint(DefaultStyles.Warn, " (build option)") |
| 17 | } |
| 18 | |
| 19 | _, _ = fmt.Fprintln(inv.Stdout, Bold(label)) |
| 20 | |
| 21 | if templateVersionParameter.DescriptionPlaintext != "" { |
| 22 | _, _ = fmt.Fprintln(inv.Stdout, " "+strings.TrimSpace(strings.Join(strings.Split(templateVersionParameter.DescriptionPlaintext, "\n"), "\n "))+"\n") |
| 23 | } |
| 24 | |
| 25 | var err error |
| 26 | var value string |
| 27 | switch { |
| 28 | case templateVersionParameter.Type == "list(string)": |
| 29 | // Move the cursor up a single line for nicer display! |
| 30 | _, _ = fmt.Fprint(inv.Stdout, "\033[1A") |
| 31 | |
| 32 | var defaults []string |
| 33 | defaultSource := defaultValue |
| 34 | if defaultSource == "" { |
| 35 | defaultSource = templateVersionParameter.DefaultValue |
| 36 | } |
| 37 | if defaultSource != "" { |
| 38 | err = json.Unmarshal([]byte(defaultSource), &defaults) |
| 39 | if err != nil { |
| 40 | return "", err |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | values, err := RichMultiSelect(inv, RichMultiSelectOptions{ |
| 45 | Options: templateVersionParameter.Options, |
| 46 | Defaults: defaults, |
| 47 | EnableCustomInput: templateVersionParameter.FormType == "tag-select", |
| 48 | }) |
| 49 | if err == nil { |
| 50 | v, err := json.Marshal(&values) |
| 51 | if err != nil { |
| 52 | return "", err |
| 53 | } |
| 54 | |
| 55 | _, _ = fmt.Fprintln(inv.Stdout) |
| 56 | pretty.Fprintf( |
| 57 | inv.Stdout, |
| 58 | DefaultStyles.Prompt, "%s\n", strings.Join(values, ", "), |
| 59 | ) |
| 60 | value = string(v) |
| 61 | } |
| 62 | case len(templateVersionParameter.Options) > 0: |
| 63 | // Move the cursor up a single line for nicer display! |
| 64 | _, _ = fmt.Fprint(inv.Stdout, "\033[1A") |
| 65 | var richParameterOption *codersdk.TemplateVersionParameterOption |
| 66 | richParameterOption, err = RichSelect(inv, RichSelectOptions{ |
| 67 | Options: templateVersionParameter.Options, |
| 68 | Default: defaultValue, |
| 69 | HideSearch: true, |
| 70 | }) |
no test coverage detected