Move fetch to clap
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 7 Mar 2018 08:32:10 +0000 (11:32 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 8 Mar 2018 20:30:46 +0000 (23:30 +0300)
src/bin/cargo.rs
src/bin/cli/fetch.rs [new file with mode: 0644]
src/bin/cli/mod.rs

index ed84f0ed2f23aa39bfecc6888e3e67eb9eb7eae6..f938572f2989df7174a1d2461bbe9b1ccf4e3504 100644 (file)
@@ -89,7 +89,7 @@ fn main() {
     };
 
     let is_clapified = ::std::env::args().any(|arg| match arg.as_ref() {
-        "build" | "bench" | "check" | "clean" | "doc" => true,
+        "build" | "bench" | "check" | "clean" | "doc" | "fetch" => true,
         _ => false
     });
 
@@ -122,7 +122,7 @@ macro_rules! each_subcommand{
 //        $mac!(check);
 //        $mac!(clean);
 //        $mac!(doc);
-        $mac!(fetch);
+//        $mac!(fetch);
         $mac!(generate_lockfile);
         $mac!(git_checkout);
         $mac!(help);
diff --git a/src/bin/cli/fetch.rs b/src/bin/cli/fetch.rs
new file mode 100644 (file)
index 0000000..068237e
--- /dev/null
@@ -0,0 +1,21 @@
+use super::utils::*;
+
+pub fn cli() -> App {
+    subcommand("fetch")
+        .about("Fetch dependencies of a package from the network")
+        .arg(
+            opt("open", "Opens the docs in a browser after the operation")
+        )
+        .arg_manifest_path()
+        .arg_locked()
+        .after_help("\
+If a lockfile is available, this command will ensure that all of the git
+dependencies and/or registries dependencies are downloaded and locally
+available. The network is never touched after a `cargo fetch` unless
+the lockfile changes.
+
+If the lockfile is not available, then this is the equivalent of
+`cargo generate-lockfile`. A lockfile is generated and dependencies are also
+all updated.
+")
+}
index 9cf8e95b5e0c4305932e8da62cc143f5aa13b9de..f1465ab13fefb3505fb175f8a2ede3a10f1e3d54 100644 (file)
@@ -182,6 +182,12 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> {
             ops::doc(&ws, &doc_opts)?;
             return Ok(());
         }
+        ("fetch", Some(args)) => {
+            config_from_args(config, args)?;
+            let ws = workspace_from_args(config, args)?;
+            ops::fetch(&ws)?;
+            return Ok(());
+        }
         _ => return Ok(())
     }
 }
@@ -249,6 +255,7 @@ See 'cargo help <command>' for more information on a specific command.
             check::cli(),
             clean::cli(),
             doc::cli(),
+            fetch::cli(),
         ])
     ;
     app
@@ -259,6 +266,7 @@ mod build;
 mod check;
 mod clean;
 mod doc;
+mod fetch;
 
 mod utils {
     use clap::{self, SubCommand, AppSettings};