diff --git a/src/bin/cargo/commands/login.rs b/src/bin/cargo/commands/login.rs index dac0457d9..1c8d3ae4c 100644 --- a/src/bin/cargo/commands/login.rs +++ b/src/bin/cargo/commands/login.rs @@ -34,10 +34,11 @@ pub fn cli() -> Command { } pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { + let registry = args.registry(config)?; ops::registry_login( config, args.get_one::("token").map(|s| s.as_str().into()), - args.get_one("registry").map(String::as_str), + registry.as_deref(), args.flag("generate-keypair"), args.flag("secret-key"), args.get_one("key-subject").map(String::as_str), diff --git a/src/bin/cargo/commands/logout.rs b/src/bin/cargo/commands/logout.rs index bc16ee55e..f1dc49cba 100644 --- a/src/bin/cargo/commands/logout.rs +++ b/src/bin/cargo/commands/logout.rs @@ -15,9 +15,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { .cli_unstable() .fail_if_stable_command(config, "logout", 8933)?; } - ops::registry_logout( - config, - args.get_one::("registry").map(String::as_str), - )?; + let registry = args.registry(config)?; + ops::registry_logout(config, registry.as_deref())?; Ok(()) } diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index ef951df95..022ec1878 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -373,16 +373,13 @@ fn login_with_generate_asymmetric_token() { fn default_registry_configured() { // When registry.default is set, login should use that one when // --registry is not used. + let _alternative = RegistryBuilder::new().alternative().build(); let cargo_home = paths::home().join(".cargo"); - cargo_home.mkdir_p(); - cargo_util::paths::write( - &cargo_home.join("config.toml"), - r#" + cargo_util::paths::append( + &cargo_home.join("config"), + br#" [registry] - default = "dummy-registry" - - [registries.dummy-registry] - index = "https://127.0.0.1/index" + default = "alternative" "#, ) .unwrap(); @@ -391,12 +388,12 @@ fn default_registry_configured() { .arg("a-new-token") .with_stderr( "\ -[UPDATING] crates.io index -[LOGIN] token for `crates.io` saved +[UPDATING] `alternative` index +[LOGIN] token for `alternative` saved ", ) .run(); - check_token(Some("a-new-token"), None); - check_token(None, Some("alternative")); + check_token(None, None); + check_token(Some("a-new-token"), Some("alternative")); } diff --git a/tests/testsuite/logout.rs b/tests/testsuite/logout.rs index 136e12e27..19f2cd9df 100644 --- a/tests/testsuite/logout.rs +++ b/tests/testsuite/logout.rs @@ -105,18 +105,18 @@ fn default_registry_configured() { .masquerade_as_nightly_cargo(&["cargo-logout"]) .with_stderr( "\ -[LOGOUT] token for `crates-io` has been removed from local storage +[LOGOUT] token for `dummy-registry` has been removed from local storage [NOTE] This does not revoke the token on the registry server. - If you need to revoke the token, visit \ + If you need to revoke the token, visit the `dummy-registry` website \ and follow the instructions there. ", ) .run(); - check_token(Some("dummy-token"), Some("dummy-registry")); - check_token(None, None); + check_token(None, Some("dummy-registry")); + check_token(Some("crates-io-token"), None); cargo_process("logout -Zunstable-options") .masquerade_as_nightly_cargo(&["cargo-logout"]) - .with_stderr("[LOGOUT] not currently logged in to `crates-io`") + .with_stderr("[LOGOUT] not currently logged in to `dummy-registry`") .run(); }