feat(vars): add interactive prompting for required variables (#2579)

This commit is contained in:
Valentin Maerten
2026-01-22 21:20:45 +01:00
committed by GitHub
parent c84cfa41f7
commit 6dedcafd7d
19 changed files with 689 additions and 17 deletions

View File

@@ -1233,6 +1233,65 @@ This is supported only for string variables.
:::
### Prompting for missing variables interactively
If you want Task to prompt users for missing required variables instead of
failing, you can enable interactive mode in your `.taskrc.yml`:
```yaml
# ~/.taskrc.yml
interactive: true
```
When enabled, Task will display an interactive prompt for any missing required
variable. For variables with an `enum`, a selection menu is shown. For variables
without an enum, a text input is displayed.
```yaml
# Taskfile.yml
version: '3'
tasks:
deploy:
requires:
vars:
- name: ENVIRONMENT
enum: [dev, staging, prod]
- VERSION
cmds:
- echo "Deploying {{.VERSION}} to {{.ENVIRONMENT}}"
```
```shell
$ task deploy
? Select value for ENVIRONMENT:
dev
staging
prod
? Enter value for VERSION: 1.0.0
Deploying 1.0.0 to prod
```
If the variable is already set (via CLI, environment, or Taskfile), no prompt
is shown:
```shell
$ task deploy ENVIRONMENT=prod VERSION=1.0.0
Deploying 1.0.0 to prod
```
::: info
Interactive prompts require a TTY (terminal). Task automatically detects
non-interactive environments like GitHub Actions, GitLab CI, and other CI
pipelines where stdin/stdout are not connected to a terminal. In these cases,
prompts are skipped and missing variables will cause an error as usual.
You can enable prompts from the command line with `--interactive` or by setting
`interactive: true` in your `.taskrc.yml`.
:::
## Variables
Task allows you to set variables using the `vars` keyword. The following

View File

@@ -301,6 +301,19 @@ Automatically answer "yes" to all prompts.
task deploy --yes
```
#### `--interactive`
Enable interactive prompts for missing required variables. When a required
variable is not provided, Task will prompt for input instead of failing.
Task automatically detects non-TTY environments (like CI pipelines) and
skips prompts. This flag can also be set in `.taskrc.yml` to enable prompts
by default.
```bash
task deploy --interactive
```
## Exit Codes
Task uses specific exit codes to indicate different types of errors:

View File

@@ -135,6 +135,20 @@ concurrency: 4
failfast: true
```
### `interactive`
- **Type**: `boolean`
- **Default**: `false`
- **Description**: Prompt for missing required variables instead of failing.
When enabled, Task will display an interactive prompt for any missing required
variable. Requires a TTY. Task automatically detects non-TTY environments
(CI pipelines, etc.) and skips prompts.
- **CLI equivalent**: [`--interactive`](./cli.md#--interactive)
```yaml
interactive: true
```
## Example Configuration
Here's a complete example of a `.taskrc.yml` file with all available options:

View File

@@ -655,7 +655,7 @@ tasks:
#### `requires`
- **Type**: `Requires`
- **Description**: Required variables with optional enums
- **Description**: Required variables with optional enum validation
```yaml
tasks:
@@ -680,6 +680,9 @@ tasks:
- ./deploy.sh
```
See [Prompting for missing variables interactively](/docs/guide#prompting-for-missing-variables-interactively)
for information on enabling interactive prompts for missing required variables.
#### `watch`
- **Type**: `bool`