Move doc to clap
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 7 Mar 2018 08:22:46 +0000 (11:22 +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/doc.rs [new file with mode: 0644]
src/bin/cli/mod.rs

index 485dc9d6203b0157b07d16b93110c31b2ffb923b..ed84f0ed2f23aa39bfecc6888e3e67eb9eb7eae6 100644 (file)
@@ -89,7 +89,7 @@ fn main() {
     };
 
     let is_clapified = ::std::env::args().any(|arg| match arg.as_ref() {
-        "build" | "bench" | "check" | "clean" => true,
+        "build" | "bench" | "check" | "clean" | "doc" => true,
         _ => false
     });
 
@@ -121,7 +121,7 @@ macro_rules! each_subcommand{
 //        $mac!(build);
 //        $mac!(check);
 //        $mac!(clean);
-        $mac!(doc);
+//        $mac!(doc);
         $mac!(fetch);
         $mac!(generate_lockfile);
         $mac!(git_checkout);
index d52f45ec380723b6cadf3c5230e82980efa25146..09afcca2ba86fd90e8274533fd7c2fd021854dad 100644 (file)
@@ -14,7 +14,7 @@ pub fn cli() -> App {
             ).multiple(true).last(true)
         )
 
-        .arg_target(
+        .arg_targets_all(
             "Benchmark only this package's library",
             "Benchmark only the specified binary",
             "Benchmark all binaries",
index 645be82794adc2d9a23df9c954186ba8ed5caf81..9316ca7a99765d9a06147d5501c7767a1be01cd5 100644 (file)
@@ -9,7 +9,7 @@ pub fn cli() -> App {
             "Exclude packages from the build",
         )
         .arg_jobs()
-        .arg_target(
+        .arg_targets_all(
             "Build only this package's library",
             "Build only the specified binary",
             "Build all binaries",
index db7277748f8c9534296b631788c2a5daaae31221..c482fb55ca19fefd8c10e2244bec17b98c282306 100644 (file)
@@ -9,7 +9,7 @@ pub fn cli() -> App {
             "Exclude packages from the check",
         )
         .arg_jobs()
-        .arg_target(
+        .arg_targets_all(
             "Check only this package's library",
             "Check only the specified binary",
             "Check all binaries",
diff --git a/src/bin/cli/doc.rs b/src/bin/cli/doc.rs
new file mode 100644 (file)
index 0000000..7e158c2
--- /dev/null
@@ -0,0 +1,42 @@
+use super::utils::*;
+
+pub fn cli() -> App {
+    subcommand("doc")
+        .about("Build a package's documentation")
+        .arg(
+            opt("open", "Opens the docs in a browser after the operation")
+        )
+        .arg_package(
+            "Package to document",
+            "Document all packages in the workspace",
+            "Exclude packages from the build",
+        )
+        .arg(
+            opt("no-deps", "Don't build documentation for dependencies")
+        )
+        .arg_jobs()
+        .arg_targets_lib_bin(
+            "Document only this package's library",
+            "Document only the specified binary",
+            "Document all binaries",
+        )
+        .arg_release("Build artifacts in release mode, with optimizations")
+        .arg_features()
+        .arg_target_triple("Build for the target triple")
+        .arg_manifest_path()
+        .arg_message_format()
+        .arg_locked()
+        .after_help("\
+By default the documentation for the local package and all dependencies is
+built. The output is all placed in `target/doc` in rustdoc's usual format.
+
+All packages in the workspace are documented if the `--all` flag is supplied. The
+`--all` flag is automatically assumed for a virtual manifest.
+Note that `--exclude` has to be specified in conjunction with the `--all` flag.
+
+If the --package argument is given, then SPEC is a package id specification
+which indicates which package should be documented. If it is not given, then the
+current package is documented. For more information on SPEC and its format, see
+the `cargo help pkgid` command.
+")
+}
index 7edf41ff5da9db7f8d490f40ebb0dbb5c4d95045..9cf8e95b5e0c4305932e8da62cc143f5aa13b9de 100644 (file)
@@ -73,7 +73,7 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> {
         let spec = Packages::from_flags(
             args.is_present("all"),
             &values(args, "exclude"),
-            &values(args, "package")
+            &values(args, "package"),
         )?;
 
         let release = mode == CompileMode::Bench || args.is_present("release");
@@ -150,7 +150,7 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> {
                 Some(profile) => {
                     let err = format_err!("unknown profile: `{}`, only `test` is \
                                        currently supported", profile);
-                    return Err(CliError::new(err, 101))
+                    return Err(CliError::new(err, 101));
                 }
             };
             let mode = CompileMode::Check { test };
@@ -170,6 +170,18 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> {
             ops::clean(&ws, &opts)?;
             return Ok(());
         }
+        ("doc", Some(args)) => {
+            config_from_args(config, args)?;
+            let ws = workspace_from_args(config, args)?;
+            let mode = ops::CompileMode::Doc { deps: !args.is_present("no-deps") };
+            let compile_opts = compile_options_from_args(config, args, mode)?;
+            let doc_opts = ops::DocOptions {
+                open_result: args.is_present("open"),
+                compile_opts,
+            };
+            ops::doc(&ws, &doc_opts)?;
+            return Ok(());
+        }
         _ => return Ok(())
     }
 }
@@ -236,6 +248,7 @@ See 'cargo help <command>' for more information on a specific command.
             build::cli(),
             check::cli(),
             clean::cli(),
+            doc::cli(),
         ])
     ;
     app
@@ -245,6 +258,7 @@ mod bench;
 mod build;
 mod check;
 mod clean;
+mod doc;
 
 mod utils {
     use clap::{self, SubCommand, AppSettings};
@@ -268,7 +282,7 @@ mod utils {
             )
         }
 
-        fn arg_target(
+        fn arg_targets_all(
             self,
             lib: &'static str,
             bin: &'static str,
@@ -281,9 +295,7 @@ mod utils {
             benchs: &'static str,
             all: &'static str,
         ) -> Self {
-            self._arg(opt("lib", lib))
-                ._arg(opt("bin", bin).value_name("NAME").multiple(true))
-                ._arg(opt("bins", bins))
+            self.arg_targets_lib_bin(lib, bin, bins)
                 ._arg(opt("example", examle).value_name("NAME").multiple(true))
                 ._arg(opt("examples", examles))
                 ._arg(opt("test", test).value_name("NAME").multiple(true))
@@ -293,6 +305,17 @@ mod utils {
                 ._arg(opt("all-targets", all))
         }
 
+        fn arg_targets_lib_bin(
+            self,
+            lib: &'static str,
+            bin: &'static str,
+            bins: &'static str,
+        ) -> Self {
+            self._arg(opt("lib", lib))
+                ._arg(opt("bin", bin).value_name("NAME").multiple(true))
+                ._arg(opt("bins", bins))
+        }
+
         fn arg_features(self) -> Self {
             self
                 ._arg(