Move clean to clap
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 7 Mar 2018 07:57:51 +0000 (10:57 +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/bench.rs
src/bin/cli/build.rs
src/bin/cli/check.rs
src/bin/cli/clean.rs [new file with mode: 0644]
src/bin/cli/mod.rs

index f3b458b01aa056e72d15a3f5587b9d1820995ba6..485dc9d6203b0157b07d16b93110c31b2ffb923b 100644 (file)
@@ -89,7 +89,7 @@ fn main() {
     };
 
     let is_clapified = ::std::env::args().any(|arg| match arg.as_ref() {
-        "build" | "bench" | "check" => true,
+        "build" | "bench" | "check" | "clean" => true,
         _ => false
     });
 
@@ -120,7 +120,7 @@ macro_rules! each_subcommand{
 //        $mac!(bench);
 //        $mac!(build);
 //        $mac!(check);
-        $mac!(clean);
+//        $mac!(clean);
         $mac!(doc);
         $mac!(fetch);
         $mac!(generate_lockfile);
index b11266cd676a25d60500aac17ccbf9f455f7e92c..d52f45ec380723b6cadf3c5230e82980efa25146 100644 (file)
@@ -37,7 +37,7 @@ pub fn cli() -> App {
         )
         .arg_jobs()
         .arg_features()
-        .arg_target_triple()
+        .arg_target_triple("Build for the target triple")
         .arg_manifest_path()
         .arg_message_format()
         .arg(
index 07691780fdf44d28d4085061b16ab83a1275408e..645be82794adc2d9a23df9c954186ba8ed5caf81 100644 (file)
@@ -23,7 +23,7 @@ pub fn cli() -> App {
         )
         .arg_release("Build artifacts in release mode, with optimizations")
         .arg_features()
-        .arg_target_triple()
+        .arg_target_triple("Build for the target triple")
         .arg_manifest_path()
         .arg_message_format()
         .arg_locked()
index 344b7c8307b16dbee95057f0ff19e31773d12293..db7277748f8c9534296b631788c2a5daaae31221 100644 (file)
@@ -27,7 +27,7 @@ pub fn cli() -> App {
                 .value_name("PROFILE")
         )
         .arg_features()
-        .arg_target_triple()
+        .arg_target_triple("Check for the target triple")
         .arg_manifest_path()
         .arg_message_format()
         .arg_locked()
diff --git a/src/bin/cli/clean.rs b/src/bin/cli/clean.rs
new file mode 100644 (file)
index 0000000..db49441
--- /dev/null
@@ -0,0 +1,20 @@
+use super::utils::*;
+
+pub fn cli() -> App {
+    subcommand("clean")
+        .about("Remove artifacts that cargo has generated in the past")
+        .arg(
+            opt("package", "Package to clean artifacts for")
+                .short("p").value_name("SPEC").multiple(true)
+        )
+        .arg_manifest_path()
+        .arg_target_triple("Target triple to clean output for (default all)")
+        .arg_release("Whether or not to clean release artifacts")
+        .arg_locked()
+        .after_help("\
+If the --package argument is given, then SPEC is a package id specification
+which indicates which package's artifacts should be cleaned out. If it is not
+given, then all packages' artifacts are removed. For more information on SPEC
+and its format, see the `cargo help pkgid` command.
+")
+}
index 71c7aeeccf62597c582445c4a3a3338e47ad24a8..7edf41ff5da9db7f8d490f40ebb0dbb5c4d95045 100644 (file)
@@ -158,6 +158,18 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> {
             ops::compile(&ws, &compile_opts)?;
             return Ok(());
         }
+        ("clean", Some(args)) => {
+            config_from_args(config, args)?;
+            let ws = workspace_from_args(config, args)?;
+            let opts = ops::CleanOptions {
+                config,
+                spec: &values(args, "package"),
+                target: args.value_of("target"),
+                release: args.is_present("release"),
+            };
+            ops::clean(&ws, &opts)?;
+            return Ok(());
+        }
         _ => return Ok(())
     }
 }
@@ -223,6 +235,7 @@ See 'cargo help <command>' for more information on a specific command.
             bench::cli(),
             build::cli(),
             check::cli(),
+            clean::cli(),
         ])
     ;
     app
@@ -231,6 +244,7 @@ See 'cargo help <command>' for more information on a specific command.
 mod bench;
 mod build;
 mod check;
+mod clean;
 
 mod utils {
     use clap::{self, SubCommand, AppSettings};
@@ -293,8 +307,8 @@ mod utils {
             self._arg(opt("release", release))
         }
 
-        fn arg_target_triple(self) -> Self {
-            self._arg(opt("target", "Build for the target triple").value_name("TRIPLE"))
+        fn arg_target_triple(self, target: &'static str) -> Self {
+            self._arg(opt("target", target).value_name("TRIPLE"))
         }
 
         fn arg_manifest_path(self) -> Self {