Allow users to input variables interactively
We could probably use Huh for this.
Previous work: https://github.com/go-task/task/issues/235 and https://github.com/go-task/task/pull/236.
Really good idea!
Do you want to make all of them interactive, or add a new interactive: bool flag?
@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}}"
@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.
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).
Hello I have opened an MR that uses bubbletea to list possible choices for vars:
https://github.com/go-task/task/pull/2379