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..105691e4353 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") diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 5c4c5cbc1d3..23840ad9a60 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -218,6 +218,8 @@ fn cargo_compile_with_wrong_manifest_path_flag() { "\ error: unexpected argument '--path' found + tip: a similar argument exists: '--manifest-path' + Usage: cargo[EXE] build [OPTIONS] For more information, try '--help'.