Allow users to input variables interactively · Issue #2079 · go-task/task · GitHub
Skip to content

Allow users to input variables interactively #2079

Description

@andreynering

We could probably use Huh for this.

Previous work: #235 and #236.

Activity

  1. self-assigned this
    on Feb 20, 2025
  2. added
    area: tuiChanges related to TUI
    and removed
    state: needs triageWaiting to be triaged by a maintainer.
    on Feb 20, 2025
  3. vmaerten commented on Feb 23, 2025

    @vmaerten
    Member

    Really good idea!
    Do you want to make all of them interactive, or add a new interactive: bool flag?

  4. andreynering commented on Feb 23, 2025

    @andreynering
    MemberAuthor

    @vmaerten Not every variable. I think it makes sense that the user chooses which vars make sense to ask. Perhaps something like this:

    tasks:
      my-task:
        cmds:
          - input: MY_VAR
          - echo "Result: {{.MY_VAR}}"

    or

    tasks:
      my-task:
        vars:
          MY_VAR: {input: true}
        cmds:
          - echo "Result: {{.MY_VAR}}"
  5. trulede commented on Mar 3, 2025

    @trulede
    Contributor

    @andreynering we did something similar for a VSCODE extension where text completion for various tasks is driven by some metadata. The metadata approach is useful as UI elements can be developed independent of the Taskfile schema. You know it under #1916 (an example is here).

    Explicitly extending Var to support such interactive use case would also be interesting. But I would suggest something like

    vars:
      FOO:
        prompt: true
        required: false
        default: {{.FOO}}
        desc: BAR
        sh: ... this is the existing schema ... so, same technique/constraints
    

    so that we can develop integrations against that. But I still prefer a metadata object ... since its more flexible. No matter what you put in the schema, it will never cover all use cases.

  6. timrulebosch commented on May 5, 2025

    @timrulebosch

    Could using the template engine work? Where a callback interface, from the template function to the UI, allows the retrieval of additional user input. The default UI would be a simple STDIN based prompt. So for example, chaining some template functions:

    tasks:
      my-task:
        vars:
          MY_VAR: '{{.MY_OTHER_VAR | prompt "foo"}}'  # prompt in "interactive-mode", with default presented to the user
          MY_VAR2: '{{.MY_OTHER_VAR | prompt "bar" | fail "VAR was not set"}}'  # mandatory, must provide
          MY_VAR3: '{{.MY_OTHER_VAR | prompt | default "fubar"}}'  # prompt with no default, then fallback to default for non-interactive case
        cmds:
           - echo "Result: {{.MY_VAR}}"

    In interactive mode, prompt returns the value from the callback, or if "Nil", then the "default" prompt value. Otherwise, in non-interactive-mode, prompt returns the "default" prompt value (so acts like default keyword).

  7. sashokbg commented on Aug 14, 2025

    @sashokbg

    Hello I have opened an MR that uses bubbletea to list possible choices for vars:

    #2379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: tuiChanges related to TUI

Fields

No fields configured for feature.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions