-
-
Notifications
You must be signed in to change notification settings - Fork 780
feat(vars): add interactive prompting for required variables #2579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add support for interactive variable prompting using Bubble Tea. Variables can be marked as `interactive: true` in the requires section, and users will be prompted to enter values for missing variables when running in a TTY. Features: - New `interactive` field on required variables - Bubble Tea-based text input and select prompts - --no-tty flag to disable interactive prompts - Automatic skip when variable is already set
- Add SyncWriter to synchronize stdout/stderr writes with prompts - Add promptMutex to serialize interactive prompts - Keep rawStdout/rawStderr for BubbleTea to avoid deadlock - Update test Taskfile with nested deps scenario
- Add collectAllRequiredVars to traverse dep tree and find missing vars - Add promptForAllVars to prompt for all vars at once - Store prompted vars on Executor and inject into all RunTask calls - Remove redundant GetTask call in collectAllRequiredVars - Make SyncWriter conditional on TTY presence
4d1f26d to
bacd724
Compare
📦 Build artifacts ready!Download binaries from this workflow run. Available platforms: Linux, macOS, Windows (amd64, arm64) |
andreynering
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a lot cooler in practice than I expected! Good job.
I liked that you added an interactive option to avoid this being a breaking change, and also that it works with enums!
You may also write a blog post for this if you want. (Or perhaps it could be a single post for this and #2564, as they'll likely be released together).
I'm holding the approve until you upgrade to Bubble Tea v2 RC, but otherwise this looks good!
| "strings" | ||
|
|
||
| "github.com/charmbracelet/bubbles/textinput" | ||
| tea "github.com/charmbracelet/bubbletea" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to import from charm.land/bubbletea/v2.
v2 is in release candidate and will be released soon!
|
Hello, @vmaerten great work! |
Summary
fixes #2079
Add interactive prompting for missing required variables using Bubble Tea UI.
When
interactive: trueis set in.taskrc.ymlor--interactiveis passed, Task will prompt users for any missing required variables instead of failing with an error.Note
I chose to bind this to requires.vars instead of defining it for each var because required vars already express the semantic of "this must be provided" so prompting is a natural fallback when they're missing.
Similar to Terraform's approach. If needed, we could add an interactive: false flag per var to opt-out, but I'm not sure it's necessary.
Features
Variable types supported
Bound to
requiresInteractive prompting only applies to variables declared in
requires.vars. Regular variables with defaults are not prompted.Configuration
Enable in
.taskrc.yml:Or via CLI flag:
Auto-detection of non-TTY environments
Task automatically detects non-TTY environments (CI, piped input, etc.) and skips prompts, failing with the standard missing variable error.
Design decisions
Hybrid approach: deps vs cmds
Task handles
depsandcmdsdifferently when it comes to prompting:Dependencies (
deps) - Upfront collectionDependencies execute in parallel, which means multiple prompts could appear simultaneously:
To avoid this, we collect all required vars upfront before any execution begins:
Commands (
cmds) - Just-in-time promptingCommands that call other tasks (
task: foo) execute sequentially, so there's no risk of interleaved prompts. We prompt just-in-time when we encounter a task with missing variables:This approach is more natural for sequential workflows - users see prompts in context as the pipeline progresses.
Why this hybrid approach?
The hybrid approach gives the best of both worlds:
Variable caching
Once a variable is prompted, its value is cached in
e.promptedVars. If the same variable is required by multiple tasks, the user is only prompted once.Handling duplicate task calls with different vars
When the same task is called multiple times with different variables:
The collection phase checks all calls, not just unique task names, ensuring we catch all missing variables.
Future considerations
Integration with
if:on tasksWhen the
if:feature on tasks lands, we'll need to ensure that tasks withif: false(that would be skipped) are not prompted for their variables during the upfront collection phase. This will require evaluating theifcondition before collecting vars from a task.Test plan
task pipelineintestdata/interactive_vars/withinteractive: true--interactive=falsedisables promptsfull-deploy(deps + cmds combined)