diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 9132f0e08..394ff2a5d 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -988,29 +988,22 @@ impl CliUnstable { pub fn fail_if_stable_opt(&self, flag: &str, issue: u32) -> CargoResult<()> { if !self.unstable_options { let see = format!( - "See https://github.com/rust-lang/cargo/issues/{} for more \ - information about the `{}` flag.", - issue, flag + "See https://github.com/rust-lang/cargo/issues/{issue} for more \ + information about the `{flag}` flag." ); // NOTE: a `config` isn't available here, check the channel directly let channel = channel(); if channel == "nightly" || channel == "dev" { bail!( - "the `{}` flag is unstable, pass `-Z unstable-options` to enable it\n\ - {}", - flag, - see + "the `{flag}` flag is unstable, pass `-Z unstable-options` to enable it\n\ + {see}" ); } else { bail!( - "the `{}` flag is unstable, and only available on the nightly channel \ - of Cargo, but this is the `{}` channel\n\ - {}\n\ - {}", - flag, - channel, - SEE_CHANNELS, - see + "the `{flag}` flag is unstable, and only available on the nightly channel \ + of Cargo, but this is the `{channel}` channel\n\ + {SEE_CHANNELS}\n\ + {see}" ); } } diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index dea7f703f..d70e86cd1 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -807,10 +807,19 @@ pub fn registry_login( let new_token; if generate_keypair || secret_key_required || key_subject.is_some() { if !config.cli_unstable().registry_auth { - // todo use fail_if_stable_opt + let flag = if generate_keypair { + "generate-keypair" + } else if secret_key_required { + "secret-key" + } else if key_subject.is_some() { + "key-subject" + } else { + unreachable!("how did whe get here"); + }; bail!( - "asymmetric token options are unstable and require the \ - `-Z registry-auth` option on the nightly channel" + "the `{flag}` flag is unstable, pass `-Z registry-auth` to enable it\n\ + See https://github.com/rust-lang/cargo/issues/10519 for more \ + information about the `{flag}` flag." ); } assert!(token.is_none()); diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index 20ef8d1ba..533309301 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -1,7 +1,7 @@ //! Tests for the `cargo login` command. use cargo_test_support::install::cargo_home; -use cargo_test_support::registry::RegistryBuilder; +use cargo_test_support::registry::{self, RegistryBuilder}; use cargo_test_support::{cargo_process, t}; use std::fs::{self}; use std::path::PathBuf; @@ -154,19 +154,25 @@ fn bad_asymmetric_token_args() { .run(); } -// todo why do theas hang when run as a test? -// #[cargo_test] -// fn asymmetric_requires_nightly() { -// cargo_process("login --key-subject=foo") -// .with_status(101) -// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel") -// .run(); -// cargo_process("login --generate-keypair") -// .with_status(101) -// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel") -// .run(); -// cargo_process("login --secret-key") -// .with_status(101) -// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel") -// .run(); -// } +#[cargo_test] +fn asymmetric_requires_nightly() { + let registry = registry::init(); + cargo_process("login --key-subject=foo") + .replace_crates_io(registry.index_url()) + .with_status(101) + .with_stderr_contains("[ERROR] the `key-subject` flag is unstable, pass `-Z registry-auth` to enable it\n\ + See https://github.com/rust-lang/cargo/issues/10519 for more information about the `key-subject` flag.") + .run(); + cargo_process("login --generate-keypair") + .replace_crates_io(registry.index_url()) + .with_status(101) + .with_stderr_contains("[ERROR] the `generate-keypair` flag is unstable, pass `-Z registry-auth` to enable it\n\ + See https://github.com/rust-lang/cargo/issues/10519 for more information about the `generate-keypair` flag.") + .run(); + cargo_process("login --secret-key") + .replace_crates_io(registry.index_url()) + .with_status(101) + .with_stderr_contains("[ERROR] the `secret-key` flag is unstable, pass `-Z registry-auth` to enable it\n\ + See https://github.com/rust-lang/cargo/issues/10519 for more information about the `secret-key` flag.") + .run(); +}