feat(cargo-each): add target-aware selection - #153
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
There are a few concrete issues to address (a doc comment typo and a now-misleading error type name), plus the README update should be confirmed as generated per repository policy.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR extends cargo-each’s selection/execution pipeline to be more Cargo-metadata-aware, adding richer package predicates, an optional OR-group for filters, and a new per-target execution mode with {target} substitution. This supports more workspace automation recipes while preserving deterministic ordering and “empty set is success” behavior.
Changes:
- Added package predicates backed by
cargo metadata(e.g.,publishable,feature:<name>,target-kind:<kind>) and introduced--filter-anyas an OR-group combined with existing--filterAND semantics. - Introduced per-target execution via
--each-target,--target-required-feature, and{target}placeholder substitution, with validation/error handling for invalid target kinds and placeholder misuse. - Updated docs and end-to-end CLI tests to cover the new filter grammar and per-target mode behavior.
File summaries
| File | Description |
|---|---|
| crates/cargo-each/tests/cli.rs | Expands the fixture workspace and adds new end-to-end tests for --filter-any, richer predicates, and per-target mode. |
| crates/cargo-each/src/workspace.rs | Extends workspace member facts gathered from cargo_metadata (publishable/features/targets) and target-kind normalization/validation helpers. |
| crates/cargo-each/src/substitute.rs | Adds {target} placeholder support and mode-aware placeholder validation for per-target execution. |
| crates/cargo-each/src/select.rs | Updates test helpers to account for new Member fields used by selection/filter logic. |
| crates/cargo-each/src/run.rs | Implements --filter-any semantics, per-target mode selection, and target-kind parsing/validation. |
| crates/cargo-each/src/plan.rs | Adds Mode::PerTarget planning: target filtering, {target} substitution, and per-target invocation construction. |
| crates/cargo-each/src/main.rs | Updates crate-level docs to describe new predicates, --filter-any, and per-target execution mode/placeholders. |
| crates/cargo-each/src/filter.rs | Extends predicate parsing/matching to include target-kind, publishable, and feature:<name>. |
| crates/cargo-each/src/error.rs | Adds InvalidTargetKindError and updates --chdir/--once error messaging to reflect per-target support. |
| crates/cargo-each/src/cli.rs | Adds CLI flags for --filter-any, --each-target, and --target-required-feature with clap-level validation. |
| crates/cargo-each/README.md | Updates user-facing README text to reflect new filter grammar and per-target mode. |
| crates/cargo-each/docs/design/README.md | Updates the design contract to include per-target mode, new predicate set, and --filter-any semantics. |
Review details
- Files reviewed: 12/12 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (97.6%) is below the target coverage (100.0%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #153 +/- ##
======================================
Coverage 97.6% 97.6%
======================================
Files 298 298
Lines 67348 67471 +123
======================================
+ Hits 65763 65886 +123
Misses 1585 1585
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The changes are cohesive, well-tested (unit + E2E), and the remaining feedback is limited to minor help-text/error-message clarity improvements.
Review details
Suppressed comments (2)
Previously missed (2) — in code that hasn't changed since the last review.
crates/cargo-each/src/cli.rs:29
long_aboutstill says "filter it by a metadata predicate", but the tool now supports broader package/target predicates and per-target mode; aligning the help text with the updated terminology will reduce confusion in--helpoutput.
crates/cargo-each/src/run.rs:97- All predicate parse failures are currently wrapped with the same context string ("invalid filter predicate"), even for
--filter-anyand--exclude-filter. Including the flag name in the context makes CLI errors more actionable when multiple predicate sources are present.
- Files reviewed: 12/12 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The changes are coherent and well-tested, with only a minor maintainability nit (duplicate supported-kind spelling list) called out in review comments.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
crates/cargo-each/src/filter.rs:71
target-kind:predicate parsing hard-codes the supported-target-kind list here, while the same list is also embedded inInvalidTargetKindError’sDisplay. Keeping these strings in sync is easy to miss; consider reusingInvalidTargetKindErrorto generate the reason instead of duplicating the list.
- Files reviewed: 12/12 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> # Conflicts: # .anvil.lock
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> # Conflicts: # .anvil.lock
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
It introduces new cargo-each execution/filter semantics and rewires many Anvil checks/templates around a new selector-cache format, which is broad and cross-cutting enough to warrant final human review.
Review details
- Files reviewed: 75/76 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> # Conflicts: # .anvil.lock
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The changes consistently apply the new selector/token contract across cargo-each, Anvil recipes/templates, and accompanying tests/docs without leaving obvious behavioral gaps in the updated surfaces.
Review details
- Files reviewed: 77/78 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> # Conflicts: # .anvil.lock
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The changes appear consistent across cargo-each, Anvil recipes, and the updated contract tests/docs, with no concrete correctness issues found in the reviewed diffs.
Review details
- Files reviewed: 77/78 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
It introduces new selection/execution semantics in cargo-each and rewires a large set of Anvil recipes, so it warrants final human review for end-to-end behavioral consistency across workflows.
Review details
- Files reviewed: 77/78 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
It changes core selection/execution semantics in cargo-each and rewires a large set of Anvil CI recipes, so a final human review is warranted despite only minor concrete issues found.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
crates/cargo-each/src/workspace.rs:129
MemberTargetsorting is intended to make per-target execution deterministic, but the current comparator only orders bynameandkinds. SinceMemberTargetalso carriesrequired_features, leaving it out means two targets that tie on name/kinds could end up with an order that depends on the upstreamcargo_metadataiteration order rather than on a fully deterministic key. Includingrequired_featuresas a final tie-breaker makes the ordering total over the captured target facts.
- Files reviewed: 78/79 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The changes are well-covered by updated tests/docs and the only remaining feedback is a minor per-target log-label disambiguation improvement.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
crates/cargo-each/src/plan.rs:143
- In per-target mode the progress label is based only on
{package}::{target_name}. Cargo packages can have multiple targets with the same name across different kinds (e.g., a lib target and the default bin target often share the package name), so this can produce duplicate labels and make logs/debugging ambiguous when multiple kinds are selected.
- Files reviewed: 78/79 changed files
- Comments generated: 0 new
- Review effort level: Lite
🤖 Extends cargo-each with Cargo-metadata-aware selection needed by more workspace recipes.
Depends on #151 so Anvil doctests exclude intentionally bin-only packages.