Skip to content

Commit

Permalink
Add warning for misuse of nextest subcommand
Browse files Browse the repository at this point in the history
Closes #302
  • Loading branch information
taiki-e committed Aug 23, 2023
1 parent a3379ff commit 4c81a32
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Diagnostics improvements. ([#302](https://github.com/taiki-e/cargo-llvm-cov/pull/302))

## [0.5.28] - 2023-08-22

- Diagnostics improvements. ([#305](https://github.com/taiki-e/cargo-llvm-cov/pull/305), [#306](https://github.com/taiki-e/cargo-llvm-cov/pull/306))
- Diagnostics improvements. ([#305](https://github.com/taiki-e/cargo-llvm-cov/pull/305), [#306](https://github.com/taiki-e/cargo-llvm-cov/pull/306))

## [0.5.27] - 2023-08-14

Expand Down
43 changes: 35 additions & 8 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ impl Args {

let mut cargo_args = vec![];
let mut subcommand = Subcommand::None;
let mut after_subcommand = false;

let mut manifest_path = None;
let mut frozen = false;
Expand Down Expand Up @@ -252,6 +253,7 @@ impl Args {
multi_arg(&arg)?;
}
Store::push(&mut $opt, &parser.value()?.into_string().unwrap())?;
after_subcommand = false;
}};
}
macro_rules! parse_opt_passthrough {
Expand Down Expand Up @@ -287,14 +289,19 @@ impl Args {
}
Value(_) => unreachable!(),
}
after_subcommand = false;
}};
}
macro_rules! parse_flag {
($flag:ident $(,)?) => {
($flag:ident $(,)?) => {{
if mem::replace(&mut $flag, true) {
multi_arg(&arg)?;
}
};
#[allow(unused_assignments)]
{
after_subcommand = false;
}
}};
}
macro_rules! parse_flag_passthrough {
($flag:ident $(,)?) => {{
Expand All @@ -303,7 +310,7 @@ impl Args {
}};
}
macro_rules! passthrough {
() => {
() => {{
match arg {
Long(flag) => {
let flag = format!("--{}", flag);
Expand All @@ -322,7 +329,8 @@ impl Args {
}
Value(_) => unreachable!(),
}
};
after_subcommand = false;
}};
}

match arg {
Expand Down Expand Up @@ -399,7 +407,10 @@ impl Args {
// show-env options
Long("export-prefix") => parse_flag!(export_prefix),

Short('v') | Long("verbose") => verbose += 1,
Short('v') | Long("verbose") => {
verbose += 1;
after_subcommand = false;
}
Short('h') | Long("help") => {
print!("{}", Subcommand::help_text(subcommand));
std::process::exit(0);
Expand All @@ -419,9 +430,7 @@ impl Args {
Long("target-dir") => unexpected(&format_arg(&arg), subcommand)?,

// Handle known options for can_passthrough=false subcommands
Short('Z') => {
parse_opt_passthrough!(());
}
Short('Z') => parse_opt_passthrough!(()),
Short('F' | 'j') | Long("features" | "jobs")
if matches!(
subcommand,
Expand Down Expand Up @@ -461,8 +470,26 @@ impl Args {
)?;
}
}
after_subcommand = true;
} else {
if after_subcommand
&& subcommand == Subcommand::Nextest
&& matches!(
val.as_str(),
// from `cargo nextest --help`
"list" | "run" | "archive" | "show-config" | "self" | "help"
)
{
// The following warning is a hint, so it should not be promoted to an error.
let _guard = term::warn::ignore();
warn!(
"note that `{val}` is treated as test filter instead of subcommand \
because `cargo llvm-cov nextest` internally calls `cargo nextest \
run`"
);
}
cargo_args.push(val);
after_subcommand = false;
}
}
_ => unexpected(&format_arg(&arg), subcommand)?,
Expand Down

0 comments on commit 4c81a32

Please sign in to comment.