From 56b8ae7c445225ab43cb9d208d764dc4dedd6903 Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 1 Dec 2021 10:29:46 +0800 Subject: [PATCH 1/3] delete --host command and message --- src/bin/cargo/commands/login.rs | 6 -- src/bin/cargo/commands/publish.rs | 2 +- src/bin/cargo/commands/search.rs | 2 +- src/cargo/util/command_prelude.rs | 23 +------- tests/testsuite/login.rs | 77 ------------------------- tests/testsuite/publish.rs | 96 ------------------------------- tests/testsuite/search.rs | 54 ----------------- 7 files changed, 4 insertions(+), 256 deletions(-) diff --git a/src/bin/cargo/commands/login.rs b/src/bin/cargo/commands/login.rs index db254948285..21afdc07ebc 100644 --- a/src/bin/cargo/commands/login.rs +++ b/src/bin/cargo/commands/login.rs @@ -10,12 +10,6 @@ pub fn cli() -> App { ) .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("token")) - // --host is deprecated (use --registry instead) - .arg( - opt("host", "Host to set the token for") - .value_name("HOST") - .hidden(true), - ) .arg(opt("registry", "Registry to use").value_name("REGISTRY")) .after_help("Run `cargo help login` for more detailed information.\n") } diff --git a/src/bin/cargo/commands/publish.rs b/src/bin/cargo/commands/publish.rs index 2120413f26c..78e6b91a559 100644 --- a/src/bin/cargo/commands/publish.rs +++ b/src/bin/cargo/commands/publish.rs @@ -32,7 +32,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let registry = args.registry(config)?; let ws = args.workspace(config)?; - let index = args.index(config)?; + let index = args.index()?; ops::publish( &ws, diff --git a/src/bin/cargo/commands/search.rs b/src/bin/cargo/commands/search.rs index 5cb3d081909..29b5e7e7132 100644 --- a/src/bin/cargo/commands/search.rs +++ b/src/bin/cargo/commands/search.rs @@ -23,7 +23,7 @@ pub fn cli() -> App { pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let registry = args.registry(config)?; - let index = args.index(config)?; + let index = args.index()?; let limit = args.value_of_u32("limit")?; let limit = min(100, limit.unwrap_or(10)); let query: Vec<&str> = args.values_of("query").unwrap_or_default().collect(); diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 9e893928850..5875db02ab2 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -613,27 +613,8 @@ pub trait ArgMatchesExt { } } - fn index(&self, config: &Config) -> CargoResult> { - // TODO: deprecated. Remove once it has been decided `--host` can be removed - // We may instead want to repurpose the host flag, as mentioned in issue - // rust-lang/cargo#4208. - let msg = "The flag '--host' is no longer valid. - -Previous versions of Cargo accepted this flag, but it is being -deprecated. The flag is being renamed to 'index', as the flag -wants the location of the index. Please use '--index' instead. - -This will soon become a hard error, so it's either recommended -to update to a fixed version or contact the upstream maintainer -about this warning."; - - let index = match self._value_of("host") { - Some(host) => { - config.shell().warn(&msg)?; - Some(host.to_string()) - } - None => self._value_of("index").map(|s| s.to_string()), - }; + fn index(&self) -> CargoResult> { + let index = self._value_of("index").map(|s| s.to_string()); Ok(index) } diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index 835461af8de..eddeecb3421 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -66,83 +66,6 @@ fn check_token(expected_token: &str, registry: Option<&str>) -> bool { } } -#[cargo_test] -fn login_with_old_credentials() { - registry::init(); - - cargo_process("login --host") - .arg(registry_url().to_string()) - .arg(TOKEN) - .run(); - - // Ensure that we get the new token for the registry - assert!(check_token(TOKEN, None)); -} - -#[cargo_test] -fn login_with_new_credentials() { - registry::init(); - setup_new_credentials(); - - cargo_process("login --host") - .arg(registry_url().to_string()) - .arg(TOKEN) - .run(); - - // Ensure that we get the new token for the registry - assert!(check_token(TOKEN, None)); -} - -#[cargo_test] -fn credentials_work_with_extension() { - registry::init(); - setup_new_credentials_toml(); - - cargo_process("login --host") - .arg(registry_url().to_string()) - .arg(TOKEN) - .run(); - - // Ensure that we get the new token for the registry - assert!(check_token(TOKEN, None)); -} - -#[cargo_test] -fn login_with_old_and_new_credentials() { - setup_new_credentials(); - login_with_old_credentials(); -} - -#[cargo_test] -fn login_without_credentials() { - registry::init(); - cargo_process("login --host") - .arg(registry_url().to_string()) - .arg(TOKEN) - .run(); - - // Ensure that we get the new token for the registry - assert!(check_token(TOKEN, None)); -} - -#[cargo_test] -fn new_credentials_is_used_instead_old() { - registry::init(); - setup_new_credentials(); - - cargo_process("login --host") - .arg(registry_url().to_string()) - .arg(TOKEN) - .run(); - - let mut config = Config::new(Shell::new(), cargo_home(), cargo_home()); - let _ = config.values(); - let _ = config.load_credentials(); - - let token = config.get_string("registry.token").unwrap().map(|p| p.val); - assert_eq!(token.unwrap(), TOKEN); -} - #[cargo_test] fn registry_credentials() { registry::alt_init(); diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index ee427435dca..1e4345b6f1c 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -185,102 +185,6 @@ See [..] validate_upload_foo(); } -// TODO: Deprecated -// remove once it has been decided --host can be removed -#[cargo_test] -fn simple_with_host() { - registry::init(); - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.0.1" - authors = [] - license = "MIT" - description = "foo" - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("publish --no-verify --token sekrit --host") - .arg(registry_url().to_string()) - .with_stderr(&format!( - "\ -[WARNING] The flag '--host' is no longer valid. - -Previous versions of Cargo accepted this flag, but it is being -deprecated. The flag is being renamed to 'index', as the flag -wants the location of the index. Please use '--index' instead. - -This will soon become a hard error, so it's either recommended -to update to a fixed version or contact the upstream maintainer -about this warning. -[UPDATING] `{reg}` index -[WARNING] manifest has no documentation, [..] -See [..] -[PACKAGING] foo v0.0.1 ([CWD]) -[UPLOADING] foo v0.0.1 ([CWD]) -", - reg = registry_path().to_str().unwrap() - )) - .run(); - - validate_upload_foo(); -} - -// TODO: Deprecated -// remove once it has been decided --host can be removed -#[cargo_test] -fn simple_with_index_and_host() { - registry::init(); - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.0.1" - authors = [] - license = "MIT" - description = "foo" - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("publish --no-verify --token sekrit --index") - .arg(registry_url().to_string()) - .arg("--host") - .arg(registry_url().to_string()) - .with_stderr(&format!( - "\ -[WARNING] The flag '--host' is no longer valid. - -Previous versions of Cargo accepted this flag, but it is being -deprecated. The flag is being renamed to 'index', as the flag -wants the location of the index. Please use '--index' instead. - -This will soon become a hard error, so it's either recommended -to update to a fixed version or contact the upstream maintainer -about this warning. -[UPDATING] `{reg}` index -[WARNING] manifest has no documentation, [..] -See [..] -[PACKAGING] foo v0.0.1 ([CWD]) -[UPLOADING] foo v0.0.1 ([CWD]) -", - reg = registry_path().to_str().unwrap() - )) - .run(); - - validate_upload_foo(); -} - #[cargo_test] fn git_deps() { registry::init(); diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index 0d239b3b455..abb709ebcb1 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -181,60 +181,6 @@ fn simple() { .run(); } -// TODO: Deprecated -// remove once it has been decided '--host' can be safely removed -#[cargo_test] -fn simple_with_host() { - setup(); - - cargo_process("search postgres --host") - .arg(registry_url().to_string()) - .with_stderr( - "\ -[WARNING] The flag '--host' is no longer valid. - -Previous versions of Cargo accepted this flag, but it is being -deprecated. The flag is being renamed to 'index', as the flag -wants the location of the index. Please use '--index' instead. - -This will soon become a hard error, so it's either recommended -to update to a fixed version or contact the upstream maintainer -about this warning. -[UPDATING] `[CWD]/registry` index -", - ) - .with_stdout_contains(SEARCH_RESULTS) - .run(); -} - -// TODO: Deprecated -// remove once it has been decided '--host' can be safely removed -#[cargo_test] -fn simple_with_index_and_host() { - setup(); - - cargo_process("search postgres --index") - .arg(registry_url().to_string()) - .arg("--host") - .arg(registry_url().to_string()) - .with_stderr( - "\ -[WARNING] The flag '--host' is no longer valid. - -Previous versions of Cargo accepted this flag, but it is being -deprecated. The flag is being renamed to 'index', as the flag -wants the location of the index. Please use '--index' instead. - -This will soon become a hard error, so it's either recommended -to update to a fixed version or contact the upstream maintainer -about this warning. -[UPDATING] `[CWD]/registry` index -", - ) - .with_stdout_contains(SEARCH_RESULTS) - .run(); -} - #[cargo_test] fn multiple_query_params() { setup(); From 64c69dffc570c72af21dd444c940416f40e1daa1 Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 1 Dec 2021 11:02:31 +0800 Subject: [PATCH 2/3] fix some bugs --- src/cargo/util/command_prelude.rs | 2 +- tests/testsuite/login.rs | 9 +-------- tests/testsuite/publish.rs | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 5875db02ab2..3afb9563b06 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -614,7 +614,7 @@ pub trait ArgMatchesExt { } fn index(&self) -> CargoResult> { - let index = self._value_of("index").map(|s| s.to_string()); + let index = self._value_of("index").map(|s| s.to_string()); Ok(index) } diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index eddeecb3421..b69616ff81b 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -1,9 +1,7 @@ //! Tests for the `cargo login` command. -use cargo::core::Shell; -use cargo::util::config::Config; use cargo_test_support::install::cargo_home; -use cargo_test_support::registry::{self, registry_url}; +use cargo_test_support::registry; use cargo_test_support::{cargo_process, paths, t}; use std::fs::{self, OpenOptions}; use std::io::prelude::*; @@ -18,11 +16,6 @@ fn setup_new_credentials() { setup_new_credentials_at(config); } -fn setup_new_credentials_toml() { - let config = cargo_home().join("credentials.toml"); - setup_new_credentials_at(config); -} - fn setup_new_credentials_at(config: PathBuf) { t!(fs::create_dir_all(config.parent().unwrap())); t!(fs::write( diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 1e4345b6f1c..9fdf4defffe 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -2,7 +2,7 @@ use cargo_test_support::git::{self, repo}; use cargo_test_support::paths; -use cargo_test_support::registry::{self, registry_path, registry_url, Package}; +use cargo_test_support::registry::{self, registry_url, Package}; use cargo_test_support::{basic_manifest, no_such_file_err_msg, project, publish}; use std::fs; From cf621fdc94bb40893149ee9e77bdb01b4ae5b092 Mon Sep 17 00:00:00 2001 From: l00556901 Date: Thu, 2 Dec 2021 10:42:52 +0800 Subject: [PATCH 3/3] modify test --- tests/testsuite/publish.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 9fdf4defffe..8085259fb2c 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -185,6 +185,32 @@ See [..] validate_upload_foo(); } +#[cargo_test] +fn simple_with_index() { + registry::init(); + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("publish --no-verify --token sekrit --index") + .arg(registry_url().to_string()) + .run(); + + validate_upload_foo(); +} + #[cargo_test] fn git_deps() { registry::init();