From bf0b33ce34ec56d68bcb7d4919d208acda743fad Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 31 Dec 2024 07:30:36 -0800 Subject: [PATCH] Make `cargo-bisect-rustc` work with hyphen or space --- .github/workflows/ci.yml | 1 - src/main.rs | 25 +++---- tests/cmd/bare-h.stdout | 52 +++++++++++++-- tests/cmd/bare-help.stdout | 132 +++++++++++++++++++++++++++++++++++-- 4 files changed, 183 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3c7604..7a01f56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,6 @@ jobs: - name: Verify that binary works run: | cargo run -- bisect-rustc --help | grep "Examples:" - cargo run -- --help | grep "Commands:" fmt: name: rustfmt diff --git a/src/main.rs b/src/main.rs index 14f6c6d..0af618e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,12 +69,6 @@ const REPORT_HEADER: &str = "\ = Copy and paste the text below into the issue report thread. Thanks! = =================================================================================="; -#[derive(Debug, Parser)] -#[command(bin_name = "cargo", subcommand_required = true)] -enum Cargo { - BisectRustc(Opts), -} - #[derive(Debug, Parser)] #[command( bin_name = "cargo bisect-rustc", @@ -397,16 +391,15 @@ impl Config { // Application entry point fn run() -> anyhow::Result<()> { env_logger::try_init()?; - let args = match Cargo::try_parse() { - Ok(Cargo::BisectRustc(args)) => args, - Err(e) => match e.context().next() { - None => { - Cargo::parse(); - unreachable!() - } - _ => Opts::parse(), - }, - }; + let mut os_args: Vec<_> = std::env::args_os().collect(); + // This allows both `cargo-bisect-rustc` (with a hyphen) and + // `cargo bisect-rustc` (with a space) to work identically. + if let Some(command) = os_args.get(1) { + if command == "bisect-rustc" { + os_args.remove(1); + } + } + let args = Opts::parse_from(os_args); let cfg = Config::from_args(args)?; if let Some(ref bound) = cfg.args.install { diff --git a/tests/cmd/bare-h.stdout b/tests/cmd/bare-h.stdout index 506af40..c450078 100644 --- a/tests/cmd/bare-h.stdout +++ b/tests/cmd/bare-h.stdout @@ -1,8 +1,50 @@ -Usage: cargo +Bisects rustc toolchains with rustup -Commands: - bisect-rustc Bisects rustc toolchains with rustup - help Print this message or the help of the given subcommand(s) +Usage: cargo bisect-rustc [OPTIONS] [-- ...] + +Arguments: + [COMMAND_ARGS]... Arguments to pass to cargo or the file specified by --script during tests Options: - -h, --help Print help + -a, --alt Download the alt build instead of normal build + --access How to access Rust git repository [default: github] [possible + values: checkout, github] + --by-commit Bisect via commit artifacts + -c, --component additional components to install + --end Right bound for search (*with* regression). You can use a date + (YYYY-MM-DD), git tag name (e.g. 1.58.0) or git commit SHA. + --force-install Force installation over existing artifacts + -h, --help Print help (see more with '--help') + --host Host triple for the compiler [default: [..]] + --install Install the given artifact + --preserve Preserve the downloaded artifacts + --preserve-target Preserve the target directory used for builds + --prompt Manually evaluate for regression with prompts + --regress Custom regression definition [default: error] [possible values: + error, success, ice, non-ice, non-error] + --script