Don't allow both --index and --registry to be specified at the same time.

Otherwise --index was being silently ignored.
This commit is contained in:
Eric Huss 2020-03-06 10:15:14 -08:00
parent 9d00f9f07f
commit 2599071110
2 changed files with 20 additions and 0 deletions

View file

@ -369,6 +369,10 @@ fn registry(
force_update: bool,
validate_token: bool,
) -> CargoResult<(Registry, SourceId)> {
if index.is_some() && registry.is_some() {
// Otherwise we would silently ignore one or the other.
bail!("both `--index` and `--registry` should not be set at the same time");
}
// Parse all configuration options
let RegistryConfig {
token: token_config,

View file

@ -1247,3 +1247,19 @@ Caused by:
.with_status(101)
.run();
}
#[cargo_test]
fn both_index_and_registry() {
let p = project().file("src/lib.rs", "").build();
for cmd in &["publish", "owner", "search", "yank --vers 1.0.0"] {
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",
)
.run();
}
}