Skip to content

Commit 60751e4

Browse files
committed
fix: check --package's value manually
1 parent da1749d commit 60751e4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/cargo/util/command_prelude.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::util::restricted_names::is_glob_pattern;
88
use crate::util::{paths, toml::TomlProfile, validate_package_name};
99
use crate::util::{
1010
print_available_benches, print_available_binaries, print_available_examples,
11-
print_available_tests,
11+
print_available_packages, print_available_tests,
1212
};
1313
use crate::CargoResult;
1414
use anyhow::bail;
@@ -52,7 +52,7 @@ pub trait AppExt: Sized {
5252
}
5353

5454
fn arg_package_spec_simple(self, package: &'static str) -> Self {
55-
self._arg(multi_opt("package", "SPEC", package).short("p"))
55+
self._arg(optional_multi_opt("package", "SPEC", package).short("p"))
5656
}
5757

5858
fn arg_package(self, package: &'static str) -> Self {
@@ -498,6 +498,13 @@ pub trait ArgMatchesExt {
498498

499499
if let Some(ws) = workspace {
500500
self.check_optional_opts(ws, &opts)?;
501+
} else if self.is_present_with_zero_values("package") {
502+
// As for cargo 0.50.0, this won't occur but if someone sneaks in
503+
// we can still provide this informative message for them.
504+
anyhow::bail!(
505+
"\"--package <SPEC>\" requires a SPEC format value.\n\
506+
Run `cargo help pkgid` for more infomation about SPEC format."
507+
)
501508
}
502509

503510
Ok(opts)
@@ -588,6 +595,10 @@ about this warning.";
588595
workspace: &Workspace<'_>,
589596
compile_opts: &CompileOptions,
590597
) -> CargoResult<()> {
598+
if self.is_present_with_zero_values("package") {
599+
print_available_packages(workspace)?
600+
}
601+
591602
if self.is_present_with_zero_values("example") {
592603
print_available_examples(workspace, compile_opts)?;
593604
}

0 commit comments

Comments
 (0)