Skip to content

Commit 8236def

Browse files
authored
Merge pull request rust-lang#4554 from RalfJung/help
improve output for 'cargo miri test --help'
2 parents e8626a3 + 20a3256 commit 8236def

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/tools/miri/cargo-miri/src/phases.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ fn forward_patched_extern_arg(args: &mut impl Iterator<Item = String>, cmd: &mut
6565
}
6666

6767
pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
68-
// Check for version and help flags even when invoked as `cargo-miri`.
69-
if has_arg_flag("--help") || has_arg_flag("-h") {
70-
show_help();
71-
return;
72-
}
73-
if has_arg_flag("--version") || has_arg_flag("-V") {
74-
show_version();
75-
return;
76-
}
77-
7868
// Require a subcommand before any flags.
7969
// We cannot know which of those flags take arguments and which do not,
8070
// so we cannot detect subcommands later.
@@ -85,11 +75,36 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
8575
"setup" => MiriCommand::Setup,
8676
"test" | "t" | "run" | "r" | "nextest" => MiriCommand::Forward(subcommand),
8777
"clean" => MiriCommand::Clean,
88-
_ =>
78+
_ => {
79+
// Check for version and help flags.
80+
if has_arg_flag("--help") || has_arg_flag("-h") {
81+
show_help();
82+
return;
83+
}
84+
if has_arg_flag("--version") || has_arg_flag("-V") {
85+
show_version();
86+
return;
87+
}
8988
show_error!(
9089
"`cargo miri` supports the following subcommands: `run`, `test`, `nextest`, `clean`, and `setup`."
91-
),
90+
)
91+
}
9292
};
93+
if has_arg_flag("--help") || has_arg_flag("-h") {
94+
match subcommand {
95+
MiriCommand::Forward(verb) => {
96+
println!("`cargo miri {verb}` supports the same flags as `cargo {verb}`:\n");
97+
let mut cmd = cargo();
98+
cmd.arg(verb);
99+
cmd.arg("--help");
100+
exec(cmd);
101+
}
102+
_ => {
103+
show_help();
104+
return;
105+
}
106+
}
107+
}
93108
let verbose = num_arg_flag("-v") + num_arg_flag("--verbose");
94109
let quiet = has_arg_flag("-q") || has_arg_flag("--quiet");
95110

0 commit comments

Comments
 (0)