Skip to content

Commit

Permalink
Auto merge of #10145 - QiangHeisenberg:deprecated, r=alexcrichton
Browse files Browse the repository at this point in the history
delete --host command and message

close #10121

The warning for this command has been around for a long time, and it seems safe to delete it now.
According to Alex's words in the issue, I think he supports deletion. I'm sorry if I misunderstood it and feel free to close it.
  • Loading branch information
bors committed Dec 14, 2021
2 parents 0bbfc5e + cf621fd commit c87b986
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 240 deletions.
6 changes: 0 additions & 6 deletions src/bin/cargo/commands/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ pub fn cli() -> App {
)
.arg_quiet()
.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")
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 2 additions & 21 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,27 +620,8 @@ pub trait ArgMatchesExt {
}
}

fn index(&self, config: &Config) -> CargoResult<Option<String>> {
// 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<Option<String>> {
let index = self._value_of("index").map(|s| s.to_string());
Ok(index)
}

Expand Down
86 changes: 1 addition & 85 deletions tests/testsuite/login.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand All @@ -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(
Expand Down Expand Up @@ -66,83 +59,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();
Expand Down
74 changes: 2 additions & 72 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -185,57 +185,8 @@ 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() {
fn simple_with_index() {
registry::init();

let p = project()
Expand All @@ -255,27 +206,6 @@ fn simple_with_index_and_host() {

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();
Expand Down
54 changes: 0 additions & 54 deletions tests/testsuite/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c87b986

Please sign in to comment.