]> git.proxmox.com Git - rustc.git/blob - src/tools/cargo/src/bin/cargo/commands/search.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / cargo / src / bin / cargo / commands / search.rs
1 use crate::command_prelude::*;
2
3 use std::cmp::min;
4
5 use cargo::ops;
6
7 pub fn cli() -> Command {
8 subcommand("search")
9 .about("Search packages in crates.io")
10 .arg(Arg::new("query").num_args(0..))
11 .arg(
12 opt(
13 "limit",
14 "Limit the number of results (default: 10, max: 100)",
15 )
16 .value_name("LIMIT"),
17 )
18 .arg_index("Registry index URL to search packages in")
19 .arg_registry("Registry to search packages in")
20 .arg_quiet()
21 .after_help(color_print::cstr!(
22 "Run `<cyan,bold>cargo help search</>` for more detailed information.\n"
23 ))
24 }
25
26 pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
27 let reg_or_index = args.registry_or_index(config)?;
28 let limit = args.value_of_u32("limit")?;
29 let limit = min(100, limit.unwrap_or(10));
30 let query: Vec<&str> = args
31 .get_many::<String>("query")
32 .unwrap_or_default()
33 .map(String::as_str)
34 .collect();
35 let query: String = query.join("+");
36 ops::search(&query, config, reg_or_index, limit)?;
37 Ok(())
38 }