about summary refs log tree commit diff
path: root/src/librustdoc
diff options
context:
space:
mode:
authorhi-rustin <rustin.liu@gmail.com>2021-11-28 15:12:56 +0800
committerhi-rustin <rustin.liu@gmail.com>2021-11-30 10:01:14 +0800
commit03be3e21b1e259b24859b8f00f5280e56bd0b254 (patch)
tree61ed5ef363130fde74a9e8d2322c08b78520b621 /src/librustdoc
parent4919988fe1765e51232558647f2260fff3544658 (diff)
Add --out-dir flag for rustdoc
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Diffstat (limited to 'src/librustdoc')
-rw-r--r--src/librustdoc/config.rs14
-rw-r--r--src/librustdoc/lib.rs11
2 files changed, 22 insertions, 3 deletions
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs
index 04bcade156a..ee19567be10 100644
--- a/src/librustdoc/config.rs
+++ b/src/librustdoc/config.rs
@@ -504,8 +504,18 @@ impl Options {
             return Err(1);
         }
 
-        let output =
-            matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc"));
+        let out_dir = matches.opt_str("out-dir").map(|s| PathBuf::from(&s));
+        let output = matches.opt_str("output").map(|s| PathBuf::from(&s));
+        let output = match (out_dir, output) {
+            (Some(_), Some(_)) => {
+                diag.struct_err("cannot use both 'out-dir' and 'output' at once").emit();
+                return Err(1);
+            }
+            (Some(out_dir), None) => out_dir,
+            (None, Some(output)) => output,
+            (None, None) => PathBuf::from("doc"),
+        };
+
         let cfgs = matches.opt_strs("cfg");
 
         let extension_css = matches.opt_str("e").map(|s| PathBuf::from(&s));
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index b6311abb5c3..8699ab20b19 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -278,7 +278,16 @@ fn opts() -> Vec<RustcOptGroup> {
             o.optopt("r", "input-format", "the input type of the specified file", "[rust]")
         }),
         stable("w", |o| o.optopt("w", "output-format", "the output type to write", "[html]")),
-        stable("o", |o| o.optopt("o", "output", "where to place the output", "PATH")),
+        stable("output", |o| {
+            o.optopt(
+                "",
+                "output",
+                "Which directory to place the output. \
+                 This option is deprecated, use --out-dir instead.",
+                "PATH",
+            )
+        }),
+        stable("o", |o| o.optopt("o", "out-dir", "which directory to place the output", "PATH")),
         stable("crate-name", |o| {
             o.optopt("", "crate-name", "specify the name of this crate", "NAME")
         }),