Skip to content

Commit

Permalink
Auto merge of #12755 - hi-rustin:rustin-patch-out-dir, r=weihanglo
Browse files Browse the repository at this point in the history
Add unsupported short suggestion for --out-dir flag
  • Loading branch information
bors committed Oct 4, 2023
2 parents 794d0a8 + 7bd0f81 commit 3f9099b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/bin/cargo/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 21 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions tests/testsuite/out_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,29 @@ fn cargo_build_out_dir() {
);
}

#[cargo_test]
fn unsupported_short_out_dir_flag() {
let p = project()
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
.build();

p.cargo("build -Z unstable-options -O")
.masquerade_as_nightly_cargo(&["out-dir"])
.with_stderr(
"\
error: unexpected argument '-O' found
tip: a similar argument exists: '--out-dir'
Usage: cargo[EXE] build [OPTIONS]
For more information, try '--help'.
",
)
.with_status(1)
.run();
}

fn check_dir_contents(
out_dir: &Path,
expected_linux: &[&str],
Expand Down

0 comments on commit 3f9099b

Please sign in to comment.