Skip to content

Replace cargo search --host with cargo search --index #4267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/bin/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::cmp;

#[derive(Deserialize)]
pub struct Options {
flag_host: Option<String>,
flag_index: Option<String>,
flag_host: Option<String>, // TODO: Depricated, remove
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
Expand All @@ -24,7 +25,8 @@ Usage:

Options:
-h, --help Print this message
--host HOST Host of a registry to search in
--index INDEX Registry index to search in
--host HOST DEPRICATED, renamed to '--index'
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
Expand All @@ -40,12 +42,37 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
options.flag_frozen,
options.flag_locked)?;
let Options {
flag_host: host,
flag_index: index,
flag_host: host, // TODO: Depricated, remove
flag_limit: limit,
arg_query: query,
..
} = options;

ops::search(&query.join("+"), config, host, cmp::min(100, limit.unwrap_or(10)) as u8)?;
// TODO: Depricated
// remove once it has been decided --host can be safely removed
// We may instead want to repurpose the host flag, as
// mentioned in this issue
// https://github.com/rust-lang/cargo/issues/4208

let msg = "The flag '--host' is no longer valid.

Previous versions of Cargo accepted this flag, but it is being
depricated. The flag is being renamed to 'index', as the flag
wants the location of the index in which to search. 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 = if host.clone().is_none() || host.clone().unwrap().is_empty() {
index
} else {
config.shell().warn(&msg)?;
host
};

ops::search(&query.join("+"), config, index, cmp::min(100, limit.unwrap_or(10)) as u8)?;
Ok(())
}
135 changes: 134 additions & 1 deletion tests/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,141 @@ fn simple() {
}

assert_that(cargo_process("search").arg("postgres")
.arg("--index").arg(registry().to_string()),
execs().with_status(0)
.with_stdout_contains("\
hoare = \"0.1.1\" # Design by contract style assertions for Rust"));
}

// TODO: Depricated
// remove once it has been decided '--host' can be safely removed
#[test]
fn simple_with_host() {
setup();

let contents = r#"{
"crates": [{
"created_at": "2014-11-16T20:17:35Z",
"description": "Design by contract style assertions for Rust",
"documentation": null,
"downloads": 2,
"homepage": null,
"id": "hoare",
"keywords": [],
"license": null,
"links": {
"owners": "/api/v1/crates/hoare/owners",
"reverse_dependencies": "/api/v1/crates/hoare/reverse_dependencies",
"version_downloads": "/api/v1/crates/hoare/downloads",
"versions": "/api/v1/crates/hoare/versions"
},
"max_version": "0.1.1",
"name": "hoare",
"repository": "https://github.com/nick29581/libhoare",
"updated_at": "2014-11-20T21:49:21Z",
"versions": null
}],
"meta": {
"total": 1
}
}"#;
let base = api_path().join("api/v1/crates");

// Older versions of curl don't peel off query parameters when looking for
// filenames, so just make both files.
//
// On windows, though, `?` is an invalid character, but we always build curl
// from source there anyway!
File::create(&base).unwrap().write_all(contents.as_bytes()).unwrap();
if !cfg!(windows) {
File::create(&base.with_file_name("crates?q=postgres&per_page=10")).unwrap()
.write_all(contents.as_bytes()).unwrap();
}

assert_that(cargo_process("search").arg("postgres")
.arg("--host").arg(registry().to_string()),
execs().with_status(0)
.with_stderr(&format!("\
[WARNING] The flag '--host' is no longer valid.

Previous versions of Cargo accepted this flag, but it is being
depricated. The flag is being renamed to 'index', as the flag
wants the location of the index in which to search. 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] registry `{reg}`
",
reg = registry()))
.with_stdout_contains("\
hoare = \"0.1.1\" # Design by contract style assertions for Rust"));
}

// TODO: Depricated
// remove once it has been decided '--host' can be safely removed
#[test]
fn simple_with_index_and_host() {
setup();

let contents = r#"{
"crates": [{
"created_at": "2014-11-16T20:17:35Z",
"description": "Design by contract style assertions for Rust",
"documentation": null,
"downloads": 2,
"homepage": null,
"id": "hoare",
"keywords": [],
"license": null,
"links": {
"owners": "/api/v1/crates/hoare/owners",
"reverse_dependencies": "/api/v1/crates/hoare/reverse_dependencies",
"version_downloads": "/api/v1/crates/hoare/downloads",
"versions": "/api/v1/crates/hoare/versions"
},
"max_version": "0.1.1",
"name": "hoare",
"repository": "https://github.com/nick29581/libhoare",
"updated_at": "2014-11-20T21:49:21Z",
"versions": null
}],
"meta": {
"total": 1
}
}"#;
let base = api_path().join("api/v1/crates");

// Older versions of curl don't peel off query parameters when looking for
// filenames, so just make both files.
//
// On windows, though, `?` is an invalid character, but we always build curl
// from source there anyway!
File::create(&base).unwrap().write_all(contents.as_bytes()).unwrap();
if !cfg!(windows) {
File::create(&base.with_file_name("crates?q=postgres&per_page=10")).unwrap()
.write_all(contents.as_bytes()).unwrap();
}

assert_that(cargo_process("search").arg("postgres")
.arg("--index").arg(registry().to_string())
.arg("--host").arg(registry().to_string()),
execs().with_status(0)
.with_stderr(&format!("\
[WARNING] The flag '--host' is no longer valid.

Previous versions of Cargo accepted this flag, but it is being
depricated. The flag is being renamed to 'index', as the flag
wants the location of the index in which to search. 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] registry `{reg}`
",
reg = registry()))
.with_stdout_contains("\
hoare = \"0.1.1\" # Design by contract style assertions for Rust"));
}
Expand Down Expand Up @@ -132,7 +265,7 @@ fn multiple_query_params() {
}

assert_that(cargo_process("search").arg("postgres").arg("sql")
.arg("--host").arg(registry().to_string()),
.arg("--index").arg(registry().to_string()),
execs().with_status(0)
.with_stdout_contains("\
hoare = \"0.1.1\" # Design by contract style assertions for Rust"));
Expand Down