Skip to content

Commit

Permalink
Correct the helper name and the tip message
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 committed Sep 21, 2023
1 parent 817c2cb commit 97656fb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn cli() -> Command {
)
.arg_features()
.arg_release("Build artifacts in release mode, with optimizations")
.arg_unsupported_mode("debug", "build", "release")
.arg_redundant_default_mode("debug", "build", "release")
.arg_profile("Build artifacts with the specified profile")
.arg_parallel()
.arg_target_triple("Build for the target triple")
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn cli() -> Command {
"debug",
"Build in debug mode (with the 'dev' profile) instead of release mode",
))
.arg_unsupported_mode("release", "install", "debug")
.arg_redundant_default_mode("release", "install", "debug")
.arg_profile("Install artifacts with the specified profile")
.arg_target_triple("Build for the target triple")
.arg_target_dir()
Expand Down
12 changes: 5 additions & 7 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,15 @@ pub trait CommandExt: Sized {
self._arg(flag("keep-going", "").value_parser(value_parser).hide(true))
}

fn arg_unsupported_mode(
fn arg_redundant_default_mode(
self,
want: &'static str,
default_mode: &'static str,
command: &'static str,
actual: &'static str,
supported_mode: &'static str,
) -> Self {
let msg = format!(
"There is no `--{want}` for `cargo {command}`. Only `--{actual}` is supported."
);
let msg = format!("`--{default_mode}` is the default for `cargo {command}`; instead `--{supported_mode}` is supported");
let value_parser = UnknownArgumentValueParser::suggest(msg);
self._arg(flag(want, "").value_parser(value_parser).hide(true))
self._arg(flag(default_mode, "").value_parser(value_parser).hide(true))
}

fn arg_targets_all(
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn incremental_config() {
}

#[cargo_test]
fn cargo_compile_with_unsupported_mode() {
fn cargo_compile_with_redundant_default_mode() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
Expand All @@ -147,7 +147,7 @@ fn cargo_compile_with_unsupported_mode() {
"\
error: unexpected argument '--debug' found
tip: There is no `--debug` for `cargo build`. Only `--release` is supported.
tip: `--debug` is the default for `cargo build`; instead `--release` is supported
Usage: cargo[EXE] build [OPTIONS]
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2445,15 +2445,15 @@ fn ambiguous_registry_vs_local_package() {
}

#[cargo_test]
fn install_with_unsupported_mode() {
fn install_with_redundant_default_mode() {
pkg("foo", "0.0.1");

cargo_process("install foo --release")
.with_stderr(
"\
error: unexpected argument '--release' found
tip: There is no `--release` for `cargo install`. Only `--debug` is supported.
tip: `--release` is the default for `cargo install`; instead `--debug` is supported
Usage: cargo[EXE] install [OPTIONS] [crate]...
Expand Down

0 comments on commit 97656fb

Please sign in to comment.