diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index ae1928e48..0e2b54da6 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -92,7 +92,7 @@ fn main() { "build" | "bench" | "check" | "clean" | "doc" | "fetch" | "generate-lockfile" | "git-checkout" | "init" | "install" | "locate-project" | "login" | "metadata" | "new" | "owner" | "package" | "pkgid" | "publish" | "read-manifest" | "run" | - "rustc" | "rustdoc" => true, + "rustc" | "rustdoc" | "search" => true, _ => false }); @@ -143,7 +143,7 @@ macro_rules! each_subcommand{ // $mac!(run); // $mac!(rustc); // $mac!(rustdoc); - $mac!(search); +// $mac!(search); $mac!(test); $mac!(uninstall); $mac!(update); diff --git a/src/bin/cli/mod.rs b/src/bin/cli/mod.rs index 08d67fe82..bd2c0f424 100644 --- a/src/bin/cli/mod.rs +++ b/src/bin/cli/mod.rs @@ -5,6 +5,7 @@ extern crate cargo; use std::slice; use std::io::{self, BufRead}; use std::path::PathBuf; +use std::cmp::min; use clap::{AppSettings, Arg, ArgMatches}; @@ -175,8 +176,7 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> { 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 to which to publish. Please -use '--index' instead. +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 @@ -488,7 +488,7 @@ about this warning."; required_features_filterable: false, }; }; - match ops::run(&ws, &compile_opts, &values(args, "args"))? { + return match ops::run(&ws, &compile_opts, &values(args, "args"))? { None => Ok(()), Some(err) => { // If we never actually spawned the process then that sounds pretty @@ -508,7 +508,7 @@ about this warning."; CliError::new(err.into(), exit_code) }) } - } + }; } ("rustc", Some(args)) => { let ws = workspace_from_args(config, args)?; @@ -543,6 +543,17 @@ about this warning."; ops::doc(&ws, &doc_opts)?; return Ok(()); } + ("search", Some(args)) => { + let registry = registry_from_args(config, args)?; + let index = index_from_args(config, args)?; + let limit: Option = args.value_of("limit") + .and_then(|v| v.parse().ok()); //FIXME: validation + let limit = min(100, limit.unwrap_or(10)); + let query: Vec<&str> = args.values_of("query").unwrap_or_default().collect(); + let query: String = query.join("+"); + ops::search(&query, config, index, limit, registry)?; + return Ok(()); + } _ => return Ok(()) } } @@ -634,6 +645,7 @@ See 'cargo help ' for more information on a specific command. run::cli(), rustc::cli(), rustdoc::cli(), + search::cli(), ]) ; app @@ -664,6 +676,7 @@ mod read_manifest; mod run; mod rustc; mod rustdoc; +mod search; mod utils { use clap::{self, SubCommand, AppSettings}; diff --git a/src/bin/cli/search.rs b/src/bin/cli/search.rs new file mode 100644 index 000000000..2bcfe193c --- /dev/null +++ b/src/bin/cli/search.rs @@ -0,0 +1,13 @@ +use super::utils::*; + +pub fn cli() -> App { + subcommand("search") + .about("Search packages in crates.io") + .arg(Arg::with_name("query").multiple(true)) + .arg_index() + .arg( + opt("limit", "Limit the number of results (default: 10, max: 100)") + .value_name("LIMIT") + ) + .arg(opt("registry", "Registry to use").value_name("REGISTRY")) +} diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 38e3b06ec..b5ecd9183 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -156,8 +156,7 @@ fn simple_with_host() { 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 to which to publish. Please -use '--index' instead. +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 @@ -224,8 +223,7 @@ fn simple_with_index_and_host() { 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 to which to publish. Please -use '--index' instead. +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 diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index 70e00f9cb..1adbaf1b2 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -137,8 +137,7 @@ fn simple_with_host() { 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 in which to search. Please -use '--index' instead. +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 @@ -204,8 +203,7 @@ fn simple_with_index_and_host() { 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 in which to search. Please -use '--index' instead. +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