Move search to clap

This commit is contained in:
Aleksey Kladov 2018-03-08 14:12:00 +03:00
parent cf06a180f9
commit 444101a6b3
5 changed files with 36 additions and 14 deletions

View File

@ -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);

View File

@ -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<u8> = 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 <command>' 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};

13
src/bin/cli/search.rs Normal file
View File

@ -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"))
}

View File

@ -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

View File

@ -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