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 <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Oct 12, 2023
1 parent 95d7909 commit 497e1ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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 497e1ee

Please sign in to comment.