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.5% 97.6%
======================================
Files 300 300
Lines 68538 69314 +776
======================================
+ Hits 66876 67652 +776
Misses 1662 1662
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
There was a problem hiding this comment.
🔵 Needs a closer look
It includes a crate version/lockfile bump that appears to conflict with the repo’s “separate release PR” convention and needs to be separated or explicitly confirmed as intended.
Review details
Suppressed comments (1)
crates/cargo-each/Cargo.toml:7
- This PR bumps cargo-each’s crate version to 0.2.0. Repo guidance is to keep version bumps in dedicated release PRs (so feature PRs don’t mix behavior changes with release bookkeeping). If this isn’t meant to be the release PR, please revert the version/lockfile bump and do it in a separate release-only PR.
version = "0.2.0"
- Files reviewed: 13/14 changed files
- Comments generated: 0 new
- Review effort level: Lite
Exercise exact diagnostics and the nesting limit so coverage and mutation gates detect parser regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The new filter/execution semantics, docs, and tests appear consistent with each other, and the changes are covered by focused unit and end-to-end tests in the touched areas.
Review details
- Files reviewed: 13/14 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🟡 Changes recommended
The design doc’s quoting guidance for metadata:<key>=<value> doesn’t fully match the implemented tokenizer behavior (metadata values containing whitespace also need quoting in compound expressions).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 13/14 changed files
- Comments generated: 1
- Review effort level: Lite
Keep parser decisions mutation-tested while excluding backward cursor mutations that can only time out. 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
The filter expression parser’s “all-atoms” fast-path can be adjusted to preserve space-in-value support while producing more helpful diagnostics for invalid multi-token inputs.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
crates/cargo-each/src/filter.rs:233
- The
all(Token::Atom)fast-path is important for supporting atomic predicates whose values contain spaces (e.g.metadata:role=script only). However, whenPredicate::parse_atom(self.spec.trim())fails (e.g.lib bin), the current early-return produces a less specific "unknown predicate" error instead of the parser's more helpful unexpected-token diagnostics. Consider attemptingparse_atomfirst and, on failure, falling back to the full expression parser so multi-token invalid inputs get better error messages without losing the space-in-value behavior.
- Files reviewed: 13/14 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
The crate version bump to 0.2.0 appears to be a release change but does not follow the documented release flow (including generating/updating the crate CHANGELOG via scripts/release-crate.ps1).
Review details
Suppressed comments (1)
crates/cargo-each/Cargo.toml:8
- This PR bumps
cargo-eachto 0.2.0, but the repository’s documented release flow expects version bumps to be done viascripts/release-crate.ps1, which also generates the crate’sCHANGELOG.md, and then submitted as a dedicated release PR after the releasable changes are already on the branch (root README.md:68-85, 98-99). In this PR the crate changelog is still empty (crates/cargo-each/CHANGELOG.md), so either drop the version bump from this feature PR or run the release script and include the generated changelog updates (and any other release artifacts) here.
name = "cargo-each"
description = "A cargo subcommand that runs a command over a cargo-style selection of workspace members"
version = "0.2.0"
readme = "README.md"
- Files reviewed: 13/14 changed files
- Comments generated: 0 new
- Review effort level: Lite
Document per-target execution in the overview and represent lib/bin filters through the shared target-kind predicate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
The crate version bump to 0.2.0 appears to be a release-oriented change but the corresponding release artifacts/process (notably the crate CHANGELOG update expected by the documented flow) are not included, so the intent needs to be clarified and made consistent.
Review details
Suppressed comments (1)
crates/cargo-each/Cargo.toml:7
cargo-eachis bumped to 0.2.0 here, but the repo’s documented publishing flow expects version bumps to be produced by./scripts/release-crate.ps1 <crate_name> [new_version], which also updates the crateCHANGELOG.md(README.md “Publishing Crates”, steps 3–4). This PR updates Cargo.toml/Cargo.lock but doesn’t updatecrates/cargo-each/CHANGELOG.md, so it’s unclear whether this is meant to be a feature PR or a release PR.
Consider either (a) reverting the version/lock bumps and doing a separate release PR via release-crate.ps1, or (b) running release-crate.ps1 cargo-each 0.2.0 and committing the resulting changelog + lock updates so the release is self-contained.
version = "0.2.0"
- Files reviewed: 13/14 changed files
- Comments generated: 0 new
- Review effort level: Lite
🤖 Releases cargo-each 0.2.0 with Cargo-metadata-aware selection and target iteration.
publishable,feature:<name>, andtarget-kind:<kind>package predicatesnot,and,or, parentheses, and conventional precedence--filterexpressions AND-combined and repeated--exclude-filterexpressions OR-combined--each-target,--target-required-feature, and{target}PATHorder on Windows--chdir, and--keep-goingsemanticsThis change is independent of the cargo-anvil adoption in #151.