Commit 45d8a36
feat(task): allow passing arguments to task dependencies via {{usage.*}} templates (#8893)
## Summary
- Task dependencies can now reference parent task arguments using
`{{usage.*}}` templates in `depends`, `depends_post`, and `wait_for`
- Arguments flow through dependency chains (A -> B -> C) — each task
parses its own usage spec and re-renders child dependency templates with
resolved values
- Works with both positional args (`arg`) and flags (`flag`), and with
both string and structured dependency syntax
### Example
```toml
[tasks.build]
usage = 'arg "<app>"'
run = 'echo "building {{usage.app}}"'
[tasks.deploy]
usage = 'arg "<app>"'
depends = [{ task = "build", args = ["{{usage.app}}"] }]
run = 'echo "deploying {{usage.app}}"'
```
```
$ mise run deploy myapp
[build] building myapp
[deploy] deploying myapp
```
Closes discussion #4331
## Implementation
Dependency templates containing `{{usage.*}}` are deferred during
initial config loading (since CLI args aren't available yet). They are
re-rendered later with actual usage values at two points:
1. **Top-level tasks** — after CLI args are resolved in `run.rs`, before
dependency graph construction
2. **Dependency chain tasks** — during `Deps::new()` graph building,
when a task receives args from its parent
Key changes:
- `Task` stores raw (unrendered) dependency templates in
`depends_raw`/`depends_post_raw`/`wait_for_raw`
- New `render_depends_with_usage()` method re-renders deps with a
`usage` context
- New `parse_usage_values_from_task()` parses a task's usage spec
against its args to extract named values
- Dependency resolution (`resolve_depends`, `all_depends`) skips deps
with unresolved `{{usage.*}}` refs
## Test plan
- [x] E2E test `test_task_dep_args` covering:
- Basic arg passing to dependency
- Flag passing to dependency
- Multiple parallel dependencies receiving the same arg
- String syntax (`depends = ["child {{usage.name}}"]`)
- Dependency chaining (A -> B -> C, args flow through all levels)
- [x] All existing dep-related e2e tests pass (dep_env, deps,
run_depends, depends_post, depends_post_multiple, deps_circular,
skip_deps, failure_hang_depends, delegation_dedup, double_dash_behavior,
args_position)
- [x] All 563 unit tests pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches task dependency resolution and graph building to defer and
later re-render dependency specs, which can affect what tasks run and
with what args across chains. Added e2e coverage reduces risk but
dependency parsing/rendering changes can have edge cases (e.g.,
`skip_deps`, mixed template/env syntax).
>
> **Overview**
> Enables `{{usage.*}}` templates inside `depends`, `depends_post`, and
`wait_for` so a task can forward its resolved usage args/flags to
dependency tasks (including through multi-level dependency chains).
>
> Implements deferred rendering for dependency entries that reference
`{{usage.*}}` by preserving raw dependency templates on `Task`, skipping
unresolved deps during initial resolution, then re-rendering them later
once CLI/parent-provided args are known (during `mise run` task list
creation and again while building the dependency graph).
>
> Adds an end-to-end test covering positional args, flags, string vs
structured dependency syntax, fan-out dependencies, and chained
forwarding, and updates docs to describe the new argument-forwarding
behavior.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
076b9c5. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>1 parent 34ae864 commit 45d8a36
File tree
6 files changed
+302
-5
lines changed- docs/tasks
- e2e/tasks
- src
- cli
- task
6 files changed
+302
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
132 | 175 | | |
133 | 176 | | |
134 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
327 | 339 | | |
328 | 340 | | |
329 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
71 | 87 | | |
72 | 88 | | |
73 | 89 | | |
| |||
0 commit comments