Skip to content

cliui: Allow entering non-default values in MultiSelect #15488

@johnstcn

Description

@johnstcn

Problem

cliui.Multiselect currently does not allow users to input custom options if zero choices are provided.

Use case

As a template author, I want to allow my users to allow setting arbitrary environment variables inside their workspace container.

I provide a parameter similar to the below:

data "coder_parameter" "env_vars" {
  name         = "env_vars"
  display_name = "Additional environment variables"
  type         = "list(string)"
  default      = jsonencode([])
  description  = "key=value pairs to set in container"
  mutable      = true
}

What I want

My users should then be able to specify additional environment variables when creating workspaces via both UI and CLI:

Additional environment variables
  key=value pairs to set in workspace environment
> foo=bar
> baz=zap
?    [Type to add an option, or press Enter to finish]
Planning workspace...

What I get

Users can specify additional environment variables via UI, but CLI does not work:

Additional environment variables
  key=value pairs to set in workspace environment <-- does not even prompt the user to add more options
Planning workspace...

The only workaround for CLI is to specify parameters via --rich-parameter-file.

Proposed Solution

cliui.MultiSelect should always allow users to specify another option.
For example, when running coder exp prompt-example multi-select:

? Select some things:  [Use arrows to move, space to select, <right> to all, <left> to none, type to filter]
> [x] Code
  [ ] Chair
  [ ] Whale
  [ ] Diamond
  [ ] Carrot
  ... Other

# Input: 🔽🔽🔽🔽🔽

? Select some things:  [Use arrows to move, space to select, <right> to all, <left> to none, type to filter]
  [x] Code
  [ ] Chair
  [ ] Whale
  [ ] Diamond
  [ ] Carrot
>  ... Other

# Input: ⏎

? Type what you want: [Enter to submit]: 
>  

# Input: potato⏎

? Select some things:  [Use arrows to move, space to select, <right> to all, <left> to none, type to filter]
  [x] Code
  [ ] Chair
  [ ] Whale
  [ ] Diamond
  [ ] Carrot
  [x] potato
>  ... Other

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliArea: CLIcustomer-requestedFeatures requested by enterprise customers. Only humans may set this.s2Broken use cases or features (with a workaround). Only humans may set this.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy