feat(clap_usage)!: expose spec(), publish against usage-lib 4 - #743
Conversation
BREAKING CHANGE: clap_usage now requires usage-lib 4. The published 2.0.3
still requires usage-lib ^2.0.3 even though the in-repo crate has built
against the workspace version for a while, so every consumer was pinned to
2.x specs.
That pin is why hk, pitchfork and communique could not adopt `effect=`:
generate() renders straight to a writer, so the Spec never escapes and
there is nothing to annotate, and 2.x has no `effect` field to set anyway.
All three ended up inlining generate()'s four lines and depending on
usage-lib directly.
Add `spec()`, which returns the Spec with `bin` already set. generate() is
now spec() plus two writeln!s, so its output is unchanged:
let mut spec = clap_usage::spec(&mut cmd, "mycli");
spec.cmd.subcommands.get_mut("rm").unwrap().effect = Some(Destructive);
println!("{spec}");
Version goes straight to 4.0.0 to match usage-lib and usage-cli; a crate
whose entire purpose is producing usage-lib types is less confusing tracking
their major than carrying its own.
Two tests: that a spec can be annotated before rendering, and that
generate() still emits the same header and body.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 12 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Central YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThe PR exposes an annotatable clap-derived specification while preserving the existing generation path.
Confidence Score: 5/5The PR appears safe to merge. The previous effect-type accessibility issue is fixed by publicly re-exporting the Important Files Changed
Reviews (2): Last reviewed commit: "fix(clap_usage): re-export usage so the ..." | Re-trigger Greptile |
The `spec()` example set `effect` via `usage::SpecCommandEffect`, but
clap_usage exported only `generate` and `spec`, so a consumer depending on
clap_usage alone could not name that type. They would have had to keep the
direct usage-lib dependency this accessor exists to remove — the example as
written would not have compiled for them.
Re-export the whole `usage` crate rather than a curated list of types, so
nothing here goes stale as usage grows:
use clap_usage::usage::SpecCommandEffect;
The integration test now reaches the enum through `clap_usage::usage::`,
which is the path an external consumer has, so it demonstrates the API is
self-sufficient instead of quietly relying on a second dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Good catch, and it went to the heart of the PR. Fixed. The Now re-exporting the whole crate rather than a curated list, so nothing goes stale as use clap_usage::usage::SpecCommandEffect;The integration test reaches the enum through Worth noting the test would have kept passing either way: an integration test in this package can reach This comment was generated by an AI coding assistant. |
clap_usage 4.0.0 is published now (jdx/usage#743), with a spec() accessor that hands back the Spec before rendering. That is exactly what was missing when this branch started: generate() writes straight to a writer, so there was nothing to annotate, and the then-current clap_usage was pinned to usage-lib 2.x, which has no effect field at all. So the four inlined lines go back to being a clap_usage call, and the direct usage-lib dependency is dropped — clap_usage re-exports usage, so `clap_usage::usage::SpecCommandEffect` covers the types the table needs. Verified: `hk usage` emits a byte-identical spec apart from min_usage_version, which moves to 4.0 since the spec now carries flag-level effects that older CLIs reject. mise.lock moves to usage 4.0.0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
clap_usage 4.0.0 is published (jdx/usage#743) with a spec() accessor that hands back the Spec before rendering — the thing that was missing when this branch started, and the reason generate()'s four lines were inlined here. The direct usage-lib dependency goes away with it: clap_usage re-exports usage, so `clap_usage::usage::SpecCommandEffect` covers what the table needs. `pitchfork usage` emits a byte-identical spec. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
codecov flagged the patch, and it was right about something real: every test here checked the tables against the CLI — complete, no stale entries, no duplicates — but none checked that `apply` actually transfers them onto the spec. The tables could have been perfect and silently never applied. `apply_annotates_commands_and_flags` covers that path directly, including that a flag with no entry is left alone rather than inheriting one. Also switches to clap_usage::spec(), now that clap_usage 4.0.0 is published (jdx/usage#743) with the accessor that was missing when this branch started. The direct usage-lib dependency goes away — clap_usage re-exports usage. `communique usage` emits a byte-identical spec. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
clap_usageon crates.io is still 2.0.3, requiringusage-lib ^2.0.3— even though the in-repo crate has been building against the workspace version for a while. Its source hasn't changed since 2.0.3, so release-plz never had a reason to bump it, and it silently fell two majors behind.That pin is why hk, pitchfork and communique couldn't adopt
effect=:generate()renders straight to a writer, so theSpecnever escapes and there's nothing to annotate; andeffectfield to set.All three ended up inlining
generate()'s four lines and depending onusage-libdirectly (jdx/hk#1121, jdx/pitchfork#666, jdx/communique#240).The addition
spec()— returns theSpecwithbinalready set:generate()is now literallyspec()plus twowriteln!s, so its output is byte-identical — there's a test asserting the header and body are unchanged.Version
Straight to 4.0.0, matching
usage-libandusage-cli. A crate whose whole purpose is producingusage-libtypes is less confusing tracking their major than carrying an independent one, and it makes the 2.x → current gap unambiguous rather than looking like a small bump.What this unblocks
Those three PRs can go back to using
clap_usageinstead of inlining it, which drops a directusage-libdependency from each and leaves them as just their effects tables plus a two-line change. I'll rework them once this releases — no rush on your side, they're correct either way, just more verbose than they need to be.Verified
cargo test --workspacepasses,clippy --all-features --all-targetsandfmt --checkclean. Two new integration tests plus a compiling doctest onspec().Note the workspace
clap_usagepin in the rootCargo.tomlalso had to move to 4.0.0 —usage-clidepends on it viaworkspace = true, so the build fails without it.This PR was generated by an AI coding assistant.
Note
Low Risk
Additive API with preserved
generate()output; main impact is the intentional semver major bump for dependents upgrading from 2.x.Overview
clap_usageis bumped to 4.0.0 (workspace and crate) so it tracksusage-lib4.x, closing the gap where crates.io still shipped 2.0.3.A new
spec()builds theusage::Specfrom aclap::Command(withbinset) and returns it for inspection or post-processing—e.g. settingeffect=on subcommands that clap cannot describe.generate()now delegates tospec()and only adds the@generatedheader and write; behavior is unchanged and covered by tests.The crate re-exports
usageand documents that consumers can depend onclap_usagealone to name types likeSpecCommandEffect. Integration tests assert annotation works throughclap_usage::usageand thatgenerateoutput is unchanged.Reviewed by Cursor Bugbot for commit 3d4004f. Bugbot is set up for automated code reviews on this repo. Configure here.