Skip to content

Commit 0c9cb5e

Browse files
committed
Add unsupported short suggestion for --out-dir flag
1 parent ec05156 commit 0c9cb5e

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/bin/cargo/commands/build.rs

Lines changed: 1 addition & 8 deletions
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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,26 @@ 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 msg = format!("no short alias is defined for `--out-dir`");
364+
let value_parser = UnknownArgumentValueParser::suggest(msg);
365+
flag("unsupported-short-out-dir-flag", "")
366+
.short('O')
367+
.value_parser(value_parser)
368+
.hide(true)
369+
};
370+
self._arg(
371+
opt(
372+
"out-dir",
373+
"Copy final artifacts to this directory (unstable)",
374+
)
375+
.value_name("PATH")
376+
.help_heading(heading::COMPILATION_OPTIONS),
377+
)
378+
._arg(unsupported_short_arg)
379+
}
360380
}
361381

362382
impl CommandExt for Command {

tests/testsuite/out_dir.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ fn unsupported_short_out_dir_flag() {
291291
.masquerade_as_nightly_cargo(&["out-dir"])
292292
.with_stderr(
293293
"\
294-
error: unexpected argument '-O' found
294+
error: unexpected argument '--unsupported-short-out-dir-flag' found
295+
296+
tip: a similar argument exists: '--out-dir'
295297
296298
Usage: cargo[EXE] build [OPTIONS]
297299

0 commit comments

Comments
 (0)