Skip to content

Commit 117eb4b

Browse files
committed
Use registry.default for login/logout
1 parent 0e13f66 commit 117eb4b

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

src/bin/cargo/commands/login.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ pub fn cli() -> Command {
3434
}
3535

3636
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
37+
let registry = args.registry(config)?;
3738
ops::registry_login(
3839
config,
3940
args.get_one::<String>("token").map(|s| s.as_str().into()),
40-
args.get_one("registry").map(String::as_str),
41+
registry.as_deref(),
4142
args.flag("generate-keypair"),
4243
args.flag("secret-key"),
4344
args.get_one("key-subject").map(String::as_str),

src/bin/cargo/commands/logout.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
1515
.cli_unstable()
1616
.fail_if_stable_command(config, "logout", 8933)?;
1717
}
18-
ops::registry_logout(
19-
config,
20-
args.get_one::<String>("registry").map(String::as_str),
21-
)?;
18+
let registry = args.registry(config)?;
19+
ops::registry_logout(config, registry.as_deref())?;
2220
Ok(())
2321
}

tests/testsuite/login.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,13 @@ fn login_with_generate_asymmetric_token() {
373373
fn default_registry_configured() {
374374
// When registry.default is set, login should use that one when
375375
// --registry is not used.
376+
let _alternative = RegistryBuilder::new().alternative().build();
376377
let cargo_home = paths::home().join(".cargo");
377-
cargo_home.mkdir_p();
378-
cargo_util::paths::write(
379-
&cargo_home.join("config.toml"),
380-
r#"
378+
cargo_util::paths::append(
379+
&cargo_home.join("config"),
380+
br#"
381381
[registry]
382-
default = "dummy-registry"
383-
384-
[registries.dummy-registry]
385-
index = "https://127.0.0.1/index"
382+
default = "alternative"
386383
"#,
387384
)
388385
.unwrap();
@@ -391,12 +388,12 @@ fn default_registry_configured() {
391388
.arg("a-new-token")
392389
.with_stderr(
393390
"\
394-
[UPDATING] crates.io index
395-
[LOGIN] token for `crates.io` saved
391+
[UPDATING] `alternative` index
392+
[LOGIN] token for `alternative` saved
396393
",
397394
)
398395
.run();
399396

400-
check_token(Some("a-new-token"), None);
401-
check_token(None, Some("alternative"));
397+
check_token(None, None);
398+
check_token(Some("a-new-token"), Some("alternative"));
402399
}

tests/testsuite/logout.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,18 @@ fn default_registry_configured() {
105105
.masquerade_as_nightly_cargo(&["cargo-logout"])
106106
.with_stderr(
107107
"\
108-
[LOGOUT] token for `crates-io` has been removed from local storage
108+
[LOGOUT] token for `dummy-registry` has been removed from local storage
109109
[NOTE] This does not revoke the token on the registry server.
110-
If you need to revoke the token, visit <https://crates.io/me> \
110+
If you need to revoke the token, visit the `dummy-registry` website \
111111
and follow the instructions there.
112112
",
113113
)
114114
.run();
115-
check_token(Some("dummy-token"), Some("dummy-registry"));
116-
check_token(None, None);
115+
check_token(None, Some("dummy-registry"));
116+
check_token(Some("crates-io-token"), None);
117117

118118
cargo_process("logout -Zunstable-options")
119119
.masquerade_as_nightly_cargo(&["cargo-logout"])
120-
.with_stderr("[LOGOUT] not currently logged in to `crates-io`")
120+
.with_stderr("[LOGOUT] not currently logged in to `dummy-registry`")
121121
.run();
122122
}

0 commit comments

Comments
 (0)