Skip to content

Commit 3f9099b

Browse files
committed
Auto merge of #12755 - hi-rustin:rustin-patch-out-dir, r=weihanglo
Add unsupported short suggestion for --out-dir flag
2 parents 794d0a8 + 7bd0f81 commit 3f9099b

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

src/bin/cargo/commands/build.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,7 @@ pub fn cli() -> Command {
3535
.arg_parallel()
3636
.arg_target_triple("Build for the target triple")
3737
.arg_target_dir()
38-
.arg(
39-
opt(
40-
"out-dir",
41-
"Copy final artifacts to this directory (unstable)",
42-
)
43-
.value_name("PATH")
44-
.help_heading(heading::COMPILATION_OPTIONS),
45-
)
38+
.arg_out_dir()
4639
.arg_build_plan()
4740
.arg_unit_graph()
4841
.arg_timings()

src/cargo/util/command_prelude.rs

+21
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,27 @@ pub trait CommandExt: Sized {
357357
.help_heading(heading::COMPILATION_OPTIONS),
358358
)
359359
}
360+
361+
fn arg_out_dir(self) -> Self {
362+
let unsupported_short_arg = {
363+
let value_parser = UnknownArgumentValueParser::suggest_arg("--out-dir");
364+
Arg::new("unsupported-short-out-dir-flag")
365+
.help("")
366+
.short('O')
367+
.value_parser(value_parser)
368+
.action(ArgAction::SetTrue)
369+
.hide(true)
370+
};
371+
self._arg(
372+
opt(
373+
"out-dir",
374+
"Copy final artifacts to this directory (unstable)",
375+
)
376+
.value_name("PATH")
377+
.help_heading(heading::COMPILATION_OPTIONS),
378+
)
379+
._arg(unsupported_short_arg)
380+
}
360381
}
361382

362383
impl CommandExt for Command {

tests/testsuite/out_dir.rs

+23
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,29 @@ fn cargo_build_out_dir() {
281281
);
282282
}
283283

284+
#[cargo_test]
285+
fn unsupported_short_out_dir_flag() {
286+
let p = project()
287+
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
288+
.build();
289+
290+
p.cargo("build -Z unstable-options -O")
291+
.masquerade_as_nightly_cargo(&["out-dir"])
292+
.with_stderr(
293+
"\
294+
error: unexpected argument '-O' found
295+
296+
tip: a similar argument exists: '--out-dir'
297+
298+
Usage: cargo[EXE] build [OPTIONS]
299+
300+
For more information, try '--help'.
301+
",
302+
)
303+
.with_status(1)
304+
.run();
305+
}
306+
284307
fn check_dir_contents(
285308
out_dir: &Path,
286309
expected_linux: &[&str],

0 commit comments

Comments
 (0)