Skip to content

Commit

Permalink
Auto merge of rust-lang#12811 - hi-rustin:rustin-patch-path, r=epage
Browse files Browse the repository at this point in the history
Better suggestion for unsupported `--path` flag
  • Loading branch information
bors committed Oct 12, 2023
2 parents e6b24be + ded92b1 commit 0d3f77f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
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
16 changes: 15 additions & 1 deletion 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 Expand Up @@ -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)
}

Expand Down
24 changes: 24 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0d3f77f

Please sign in to comment.