Move search to clap
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 8 Mar 2018 11:12:00 +0000 (14:12 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 8 Mar 2018 20:30:47 +0000 (23:30 +0300)
src/bin/cargo.rs
src/bin/cli/mod.rs
src/bin/cli/search.rs [new file with mode: 0644]
tests/testsuite/publish.rs
tests/testsuite/search.rs

index ae1928e4804840aaaeffb2260c853958548de884..0e2b54da67ebe6caceab4665e40d6020334d9c3b 100644 (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);
index 08d67fe82c7c30541fd96ffce533b0946459d8ca..bd2c0f4242e7b4febe7f901596a9a9c31ba4145d 100644 (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};
diff --git a/src/bin/cli/search.rs b/src/bin/cli/search.rs
new file mode 100644 (file)
index 0000000..2bcfe19
--- /dev/null
@@ -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"))
+}
index 38e3b06ecf032a206a4f96a65a147f324fd8a12b..b5ecd91830fc8c9b1e044c51e28fa95c0d9b8d39 100644 (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
index 70e00f9cbfeae7e387783609411efb61d31b0ddc..1adbaf1b2705499ca457e086a85a81cbd890cedd 100644 (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