Skip to content

Migrate CLI parsing from clap to usage-rs - #145

Open
edmundmiller wants to merge 2 commits into
mainfrom
cursor/migrate-to-usage-rs-0231
Open

Migrate CLI parsing from clap to usage-rs#145
edmundmiller wants to merge 2 commits into
mainfrom
cursor/migrate-to-usage-rs-0231

Conversation

@edmundmiller

@edmundmiller edmundmiller commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Replace clap with usage-rs 6.1.1 for rustqc argument parsing, following the clap migration guide. QC algorithms and the BAM pass are unchanged.

What changed

  • Depend on usage = { package = "usage-rs", version = "6.1.1", features = ["completions"] } instead of clap 4.
  • #[derive(Parser)] / #[derive(Subcommand)] become #[derive(usage::Cli)] / #[derive(usage::Subcommands)] / #[derive(usage::Args)].
  • Strandedness now derives usage::ValueEnum (still serde::Deserialize + Display). Library consumers that treated it as clap’s ValueEnum need to switch; parsing via serde YAML is unchanged.
  • --version still prints crate version, git hash, build timestamp, and the runtime CPU info line. -V stays short.
  • Hidden endpoints from usage: __usage_spec__ (portable KDL) and __complete_word__ (runtime completions).
  • Docs/credits/AGENTS.md/CONTRIBUTING.md no longer claim clap.
  • MSRV is 1.91 (usage-rs 6.1.1’s requirement; was 1.87).
  • crossbeam-epoch updated to 0.9.20 for RUSTSEC-2026-0204.

cargo tree -i clap reports no clap crate in the app graph.

Intentional flag / help diffs

User-facing flags, shorts, env vars, defaults, and requiredness are the same. Parse errors and --help/--version still exit 2 / 0.

Help text is now rendered by usage, not clap’s custom help_template:

  • Synopsis is rustqc rna <FLAGS> <INPUT>… rather than clap’s [OPTIONS] <INPUT>....
  • Long help lists author and license from crate metadata.
  • usage synthesizes a help subcommand (clap did this too by default).
  • Unknown flags are rejected (unknown_flags = "error"); repeated scalar flags are rejected (args_override_self = false).
  • Prefix matching is unsupported (usage does not infer --thr--threads). Full names or declared aliases only.

Regenerating completions / docs

usage-rs is experimental; pin producers and consumers to 6.1.1.

# Dump the spec (also `Cli::to_kdl()` in-process)
cargo run --quiet -- __usage_spec__ > rustqc.usage.kdl

# Same usage-cli revision as usage-rs
usage g markdown -f rustqc.usage.kdl --out-dir docs
usage g manpage -f rustqc.usage.kdl > rustqc.1
usage g completion bash rustqc --file rustqc.usage.kdl

Shell completion scripts can also be produced in-process with Cli::completion_script(usage::complete::Shell::…).

Verification

  • cargo +stable fmt --check and cargo +stable clippy -- -D warnings pass.
  • cargo +stable test: 200 lib unit tests, 15 binary CLI tests, and 18 integration tests passed.
  • Smoke-tested rustqc --help, -h, --version, -V, rna --help, missing --gtf (exit 2), and unknown flags (exit 2).
  • First CI run failed MSRV (1.87 vs usage-rs’s 1.91) and audit (crossbeam-epoch); both are addressed in the follow-up commit.
Open in Web Open in Cursor 

Replace clap derive parsing with usage-rs 6.1.1 so rustqc keeps the
same flags, shorts, env vars, and defaults while gaining a portable
usage spec for completions, manpages, and docs.

Co-authored-by: Edmund Miller <edmundmiller@users.noreply.github.com>
@edmundmiller
edmundmiller marked this pull request as ready for review August 23, 2026 16:42
usage-rs 6.1.1 requires rustc 1.91. Bump rust-version and the CI MSRV
job to match. Update crossbeam-epoch to 0.9.20 for RUSTSEC-2026-0204.

Co-authored-by: Edmund Miller <edmundmiller@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants