refactor: --registry always conflicts with --index

Move the validation upfront to clap
This commit is contained in:
Weihang Lo 2023-09-15 22:11:10 +08:00
parent 1f172e4b76
commit e57ce13da8
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
2 changed files with 9 additions and 5 deletions

View File

@ -291,7 +291,12 @@ pub trait CommandExt: Sized {
}
fn arg_index(self, help: &'static str) -> Self {
self._arg(opt("index", help).value_name("INDEX"))
// Always conflicts with `--registry`.
self._arg(
opt("index", help)
.value_name("INDEX")
.conflicts_with("registry"),
)
}
fn arg_dry_run(self, dry_run: &'static str) -> Self {

View File

@ -1389,10 +1389,9 @@ fn both_index_and_registry() {
p.cargo(cmd)
.arg("--registry=foo")
.arg("--index=foo")
.with_status(101)
.with_stderr(
"[ERROR] both `--index` and `--registry` \
should not be set at the same time",
.with_status(1)
.with_stderr_contains(
"error: the argument '--registry <REGISTRY>' cannot be used with '--index <INDEX>'",
)
.run();
}