mirror of
https://github.com/go-task/task.git
synced 2026-06-26 06:06:07 +00:00
feat(cmd): add ask option to commands
Add an `ask` attribute to commands that shows a y/n confirmation
before executing. If the user declines, the command is skipped but
the task continues with the next command.
Example:
```yaml
cmds:
- cmd: echo "Deploying..."
ask: "Deploy to production?"
- task: run-migrations
ask: "Run database migrations?"
```
Behavior:
- Default: asks for y/n confirmation
- --yes: auto-confirms all asks
- --dry: shows commands without asking
This differs from task-level `prompt:` which cancels the entire task
if declined. Command-level `ask:` only skips the individual command.
This commit is contained in:
@@ -741,6 +741,8 @@ tasks:
|
||||
platforms: [linux, darwin]
|
||||
set: [errexit]
|
||||
shopt: [globstar]
|
||||
if: '[ "$CI" = "true" ]'
|
||||
ask: "Run this command?"
|
||||
```
|
||||
|
||||
### Task References
|
||||
@@ -857,6 +859,36 @@ tasks:
|
||||
if: '[ "{{.ITEM}}" != "b" ]'
|
||||
```
|
||||
|
||||
### Command Confirmations
|
||||
|
||||
Use `ask` to request user confirmation before executing a command. If the
|
||||
user declines (answers "n" or "no"), the command is skipped but the task
|
||||
continues.
|
||||
|
||||
```yaml
|
||||
tasks:
|
||||
deploy:
|
||||
cmds:
|
||||
- cmd: echo "Deploying to production..."
|
||||
ask: "Deploy to production?"
|
||||
- cmd: echo "Updating database..."
|
||||
ask: "Run database migrations?"
|
||||
- echo "Done!" # No ask, always runs
|
||||
```
|
||||
|
||||
| Flag | Behavior |
|
||||
|------|----------|
|
||||
| (none) | Asks user for y/n confirmation |
|
||||
| `--yes` | Auto-confirms all asks |
|
||||
| `--dry` | Shows commands without asking |
|
||||
|
||||
:::note
|
||||
|
||||
This is different from the task-level `prompt:` which cancels the entire task
|
||||
if declined. Command-level `ask:` only skips the individual command.
|
||||
|
||||
:::
|
||||
|
||||
## Shell Options
|
||||
|
||||
### Set Options
|
||||
|
||||
@@ -340,6 +340,10 @@
|
||||
"if": {
|
||||
"description": "A shell command to evaluate. If the exit code is non-zero, the command is skipped.",
|
||||
"type": "string"
|
||||
},
|
||||
"ask": {
|
||||
"description": "A y/n confirmation shown before executing this task call. If declined, the task call is skipped.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
@@ -381,6 +385,10 @@
|
||||
"if": {
|
||||
"description": "A shell command to evaluate. If the exit code is non-zero, the command is skipped.",
|
||||
"type": "string"
|
||||
},
|
||||
"ask": {
|
||||
"description": "A y/n confirmation shown before executing this command. If declined, the command is skipped.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
|
||||
Reference in New Issue
Block a user