Move rustdoc to clap
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 8 Mar 2018 10:16:17 +0000 (13:16 +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/rustdoc.rs [new file with mode: 0644]

index 81be94cd827e27f4579170f6d1aa0855fee6e5fe..ae1928e4804840aaaeffb2260c853958548de884 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" => true,
+        "rustc" | "rustdoc" => true,
         _ => false
     });
 
@@ -142,7 +142,7 @@ macro_rules! each_subcommand{
 //        $mac!(read_manifest);
 //        $mac!(run);
 //        $mac!(rustc);
-        $mac!(rustdoc);
+//        $mac!(rustdoc);
         $mac!(search);
         $mac!(test);
         $mac!(uninstall);
index 25d9aeb2f5316fbe9f105f2cff6b6d16eb53ee81..a1b0125cef7a4fb8cd2c4422f1baae0306ec2ae4 100644 (file)
@@ -514,6 +514,20 @@ about this warning.";
             ops::compile(&ws, &compile_opts)?;
             return Ok(());
         }
+        ("rustdoc", Some(args)) => {
+            let ws = workspace_from_args(config, args)?;
+            let mode = CompileMode::Doc { deps: false };
+            let mut compile_opts = compile_options_from_args(config, args, mode)?;
+            let packages = values(args, "package");
+            compile_opts.spec = Packages::Packages(&packages);
+            compile_opts.target_rustdoc_args = Some(&values(args, "args"));
+            let doc_opts = ops::DocOptions {
+                open_result: args.is_present("open"),
+                compile_opts
+            };
+            ops::doc(&ws, &doc_opts)?;
+            return Ok(());
+        }
         _ => return Ok(())
     }
 }
@@ -604,6 +618,7 @@ See 'cargo help <command>' for more information on a specific command.
             read_manifest::cli(),
             run::cli(),
             rustc::cli(),
+            rustdoc::cli(),
         ])
     ;
     app
@@ -633,6 +648,7 @@ mod publish;
 mod read_manifest;
 mod run;
 mod rustc;
+mod rustdoc;
 
 mod utils {
     use clap::{self, SubCommand, AppSettings};
diff --git a/src/bin/cli/rustdoc.rs b/src/bin/cli/rustdoc.rs
new file mode 100644 (file)
index 0000000..031dbbb
--- /dev/null
@@ -0,0 +1,44 @@
+use clap::AppSettings;
+
+use super::utils::*;
+
+pub fn cli() -> App {
+    subcommand("rustdoc")
+        .setting(AppSettings::TrailingVarArg)
+        .about("Build a package's documentation, using specified custom flags.")
+        .arg(Arg::with_name("args").multiple(true))
+        .arg(opt("open", "Opens the docs in a browser after the operation"))
+        .arg(
+            opt("package", "Package to document")
+                .short("p").value_name("SPEC")
+        )
+        .arg_jobs()
+        .arg_targets_all(
+            "Build only this package's library",
+            "Build only the specified binary",
+            "Build all binaries",
+            "Build only the specified example",
+            "Build all examples",
+            "Build only the specified test target",
+            "Build all tests",
+            "Build only the specified bench target",
+            "Build all benches",
+            "Build all targets (default)",
+        )
+        .arg_release("Build artifacts in release mode, with optimizations")
+        .arg_manifest_path()
+        .arg_message_format()
+        .after_help("\
+The specified target for the current package (or package specified by SPEC if
+provided) will be documented with the specified <opts>... being passed to the
+final rustdoc invocation. Dependencies will not be documented as part of this
+command.  Note that rustdoc will still unconditionally receive arguments such
+as -L, --extern, and --crate-type, and the specified <opts>...  will simply be
+added to the rustdoc invocation.
+
+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.
+")
+}