diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs index d503f43ddcc..083b43e45ea 100644 --- a/src/bin/cargo/commands/build.rs +++ b/src/bin/cargo/commands/build.rs @@ -35,14 +35,7 @@ pub fn cli() -> Command { .arg_parallel() .arg_target_triple("Build for the target triple") .arg_target_dir() - .arg( - opt( - "out-dir", - "Copy final artifacts to this directory (unstable)", - ) - .value_name("PATH") - .help_heading(heading::COMPILATION_OPTIONS), - ) + .arg_out_dir() .arg_build_plan() .arg_unit_graph() .arg_timings() diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index bd8889bef2c..a8b8e31c7eb 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -357,6 +357,27 @@ pub trait CommandExt: Sized { .help_heading(heading::COMPILATION_OPTIONS), ) } + + fn arg_out_dir(self) -> Self { + let unsupported_short_arg = { + let value_parser = UnknownArgumentValueParser::suggest_arg("--out-dir"); + Arg::new("unsupported-short-out-dir-flag") + .help("") + .short('O') + .value_parser(value_parser) + .action(ArgAction::SetTrue) + .hide(true) + }; + self._arg( + opt( + "out-dir", + "Copy final artifacts to this directory (unstable)", + ) + .value_name("PATH") + .help_heading(heading::COMPILATION_OPTIONS), + ) + ._arg(unsupported_short_arg) + } } impl CommandExt for Command { diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/out_dir.rs index 03add9ac860..83621a2d2d9 100644 --- a/tests/testsuite/out_dir.rs +++ b/tests/testsuite/out_dir.rs @@ -293,6 +293,8 @@ fn unsupported_short_out_dir_flag() { "\ error: unexpected argument '-O' found + tip: a similar argument exists: '--out-dir' + Usage: cargo[EXE] build [OPTIONS] For more information, try '--help'.