Skip to content

Commit

Permalink
Better suggestion for unsupported -path flag
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <[email protected]>
  • Loading branch information
Rustin170506 committed Oct 12, 2023
1 parent 95d7909 commit 73bfbbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,24 @@ 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(
opt("manifest-path", "Path to Cargo.toml")
.value_name("PATH")
.help_heading(heading::MANIFEST_OPTIONS),
)
._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")
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down

0 comments on commit 73bfbbb

Please sign in to comment.