Skip to content

Commit e57ce13

Browse files
committed
refactor: --registry always conflicts with --index
Move the validation upfront to clap
1 parent 1f172e4 commit e57ce13

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/cargo/util/command_prelude.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,12 @@ pub trait CommandExt: Sized {
291291
}
292292

293293
fn arg_index(self, help: &'static str) -> Self {
294-
self._arg(opt("index", help).value_name("INDEX"))
294+
// Always conflicts with `--registry`.
295+
self._arg(
296+
opt("index", help)
297+
.value_name("INDEX")
298+
.conflicts_with("registry"),
299+
)
295300
}
296301

297302
fn arg_dry_run(self, dry_run: &'static str) -> Self {

tests/testsuite/alt_registry.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,10 +1389,9 @@ fn both_index_and_registry() {
13891389
p.cargo(cmd)
13901390
.arg("--registry=foo")
13911391
.arg("--index=foo")
1392-
.with_status(101)
1393-
.with_stderr(
1394-
"[ERROR] both `--index` and `--registry` \
1395-
should not be set at the same time",
1392+
.with_status(1)
1393+
.with_stderr_contains(
1394+
"error: the argument '--registry <REGISTRY>' cannot be used with '--index <INDEX>'",
13961395
)
13971396
.run();
13981397
}

0 commit comments

Comments
 (0)