diff --git a/src/bin/cargo/commands/add.rs b/src/bin/cargo/commands/add.rs index 344cd2af3f8..e1ece14b811 100644 --- a/src/bin/cargo/commands/add.rs +++ b/src/bin/cargo/commands/add.rs @@ -77,7 +77,7 @@ Example uses: "Ignore `rust-version` specification in packages (unstable)" ), ]) - .arg_manifest_path() + .arg_manifest_path_without_unsupported_path_tip() .arg_package("Package to modify") .arg_dry_run("Don't actually write the manifest") .arg_quiet() diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 25176cb22d1..f5b897ea710 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -267,6 +267,20 @@ pub trait CommandExt: Sized { } fn arg_manifest_path(self) -> Self { + // We use `--manifest-path` instead of `--path`. + let unsupported_path_arg = { + let value_parser = UnknownArgumentValueParser::suggest_arg("--manifest-path"); + flag("unsupported-path-flag", "") + .long("path") + .value_parser(value_parser) + .hide(true) + }; + self.arg_manifest_path_without_unsupported_path_tip() + ._arg(unsupported_path_arg) + } + + // `cargo add` has a `--path` flag to install a crate from a local path. + fn arg_manifest_path_without_unsupported_path_tip(self) -> Self { self._arg( opt("manifest-path", "Path to Cargo.toml") .value_name("PATH") @@ -358,7 +372,7 @@ pub trait CommandExt: Sized { .value_parser(value_parser) .hide(true) }; - self._arg(flag("quiet", "Do not print cargo log messages").short('q')) + self.arg_quiet_without_unknown_silent_arg_tip() ._arg(unsupported_silent_arg) } diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index fdb8a4d7a4c..23840ad9a60 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -205,6 +205,30 @@ fn cargo_compile_manifest_path() { assert!(p.bin("foo").is_file()); } +#[cargo_test] +fn cargo_compile_with_wrong_manifest_path_flag() { + let p = project() + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/foo.rs", &main_file(r#""i am foo""#, &[])) + .build(); + + p.cargo("build --path foo/Cargo.toml") + .cwd(p.root().parent().unwrap()) + .with_stderr( + "\ +error: unexpected argument '--path' found + + tip: a similar argument exists: '--manifest-path' + +Usage: cargo[EXE] build [OPTIONS] + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); +} + #[cargo_test] fn chdir_gated() { let p = project()