feat(lib): add usage-rs facade - #953
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Central YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Greptile SummaryThe PR adds the
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (5): Last reviewed commit: "chore: include usage-rs in msrv checks" | Re-trigger Greptile |
Instruction counts
No instruction-count regression above 1%. Only instruction counts gate. Wall clock is shown for context — on identical hardware it moves 4-20% run to run. Measured by tak — instruction-counted CLI benchmarks, stored in this repository's git notes. Shadow comparisonParsing
|
07d5e90 to
2efb559
Compare
9dab4ae to
dbfd49e
Compare
2a452a0 to
5c280bf
Compare
|
No reviewable files after applying ignore patterns. |
## Summary
- add `usage-rs`, the single dependency for compiled usage CLIs
- re-export the four derives, the argv runtime, and `ValueHint` from the
facade
- forward cold-path `spec`, `help`, `completions`, and `diagnostics`
features
- make generated derive paths resolve either `usage-rs` or a
direct/renamed `usage-argv` dependency
- retain direct `usage-argv` compatibility for low-level adopters
Applications can choose the short public crate name in Cargo:
```toml
[dependencies]
usage = { package = "usage-rs", version = "5.1" }
```
and then keep the declaration on one API:
```rust
use usage::Cli;
#[derive(Cli)]
struct Cli {
#[usage(long, value_hint = usage::ValueHint::FilePath)]
file: Option<std::path::PathBuf>,
}
```
## Why
Depending on `usage-derive` and `usage-argv` separately exposes an
implementation split and allows their versions or features to drift. The
facade gives adopters one versioned package while leaving the
zero-allocation runtime independently usable.
The facade crate target remains `usage_rs` to avoid colliding with the
existing `usage-lib` target inside this workspace. The documented Cargo
alias provides the intended `usage::…` source spelling.
## Stack
Base layer for #965, which migrates `usage-cli` to this facade.
## Checks
- `cargo test --all --all-features`
- `cargo clippy --all --all-features --all-targets -- -D warnings`
- `cargo +1.91.0 check -p usage-argv -p usage-derive -p usage-rs
--all-features`
- `cargo test -p usage-rs --no-default-features`
- external path-dependency check using the documented `usage = { package
= "usage-rs", … }` alias
_This PR was generated by Codex._
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Macro-generated path resolution affects every derived CLI; behavior is
covered by new fixtures, but a wrong `crate_name` resolution could break
adopters at compile time across the ecosystem.
>
> **Overview**
> Introduces **`usage-rs`**, a workspace crate meant to be depended on
as `usage = { package = "usage-rs", … }`. It re-exports
**`usage-argv`**, optional **`usage-derive`** macros behind the `spec`
feature, and forwards feature flags for help, completions, and
diagnostics so adopters get one versioned package instead of splitting
derive and runtime.
>
> **`usage-derive`** now uses **`proc-macro-crate`** to pick emitted
paths at compile time: a direct **`usage-argv`** dependency wins over
the facade (for mixed/low-level setups); otherwise generated code goes
through **`usage-rs::argv`** and the facade’s derive re-exports. Emitted
tables import the chosen runtime as `usage_argv` locally, and unit
subcommands use the resolved derive path instead of hard-coded
`::usage_derive`.
>
> Docs and model hints shift public examples from
`usage_argv::ValueHint` to **`usage::ValueHint`**. CI MSRV matrix
includes **`usage-rs`** at Rust 1.91; integration tests cover the Cargo
alias fixture and mixed direct + facade dependencies.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
8fe3c3c. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Replaces #953 after flipping the stack so the CLI can consume the
facade.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added the `usage-rs` facade crate, providing a unified API for CLI
parsing and derive macros.
* Added support for runtime-selected parsing, completions, settings,
metadata, validation, and subcommands.
* Improved file-path handling with clearer errors for invalid UTF-8 and
platform conversion failures.
* **Bug Fixes**
* Updated generated APIs and examples to use the unified `usage`
interface consistently.
* **Tests**
* Added coverage for argument parsing, subcommands, value hints, and
generated metadata.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
usage-rs, the single dependency for compiled usage CLIsValueHintfrom the facadespec,help,completions, anddiagnosticsfeaturesusage-rsor a direct/renamedusage-argvdependencyusage-argvcompatibility for low-level adoptersApplications can choose the short public crate name in Cargo:
and then keep the declaration on one API:
Why
Depending on
usage-deriveandusage-argvseparately exposes an implementation split and allows their versions or features to drift. The facade gives adopters one versioned package while leaving the zero-allocation runtime independently usable.The facade crate target remains
usage_rsto avoid colliding with the existingusage-libtarget inside this workspace. The documented Cargo alias provides the intendedusage::…source spelling.Stack
Targets #951, which introduces the usage-owned
ValueHintre-exported here.Checks
cargo test --all --all-featurescargo clippy --all --all-features --all-targets -- -D warningscargo +1.91.0 check -p usage-argv -p usage-derive -p usage-rs --all-featurescargo check -p usage-rs --no-default-featuresusage = { package = "usage-rs", … }aliasThis PR was generated by Codex.
Note
Low Risk
Mostly additive packaging and path resolution in proc-macro codegen; direct
usage-argvusage remains supported, with limited blast radius beyond new adopters choosing the facade.Overview
Introduces
usage-rs, a facade so compiled CLI apps can depend on one Cargo package (e.g.usage = { package = "usage-rs", … }) instead of splittingusage-deriveandusage-argv.The crate re-exports the argv runtime (including
ValueHint), optionally re-exportsCli,Args,Subcommands, andValueEnumbehind thespecfeature, and forwardshelp,completions, anddiagnosticsto the underlying crates.usage-derivecodegen now prefers resolving runtime and derive paths throughusage-rs(including renamed package aliases), with the previous directusage-argv/usage-derivepaths kept for low-level adopters.Workspace wiring adds the new member, lockfile entry, and MSRV CI coverage for
usage-rs.Reviewed by Cursor Bugbot for commit 5c280bf. Bugbot is set up for automated code reviews on this repo. Configure here.