about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorJames Munns <james.munns@ferrous-systems.com>2019-01-10 20:37:51 +0100
committerSteve Klabnik <steve@steveklabnik.com>2019-01-30 09:13:17 -0500
commit7389f97cde3da06fd7025e3eb93f4ab3c10c7d40 (patch)
tree8a1096887c20cfb8869623a75b69fc3c9906cded /src/tools
parent43b4c4a36b6c189bf0718a9d77ff1164c3fa7cac (diff)
downloadrust-7389f97cde3da06fd7025e3eb93f4ab3c10c7d40.tar.gz
rust-7389f97cde3da06fd7025e3eb93f4ab3c10c7d40.zip
Only the compatibility items from the embedded book PR
PR: https://github.com/rust-lang/rust/pull/56291
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/rustbook/Cargo.toml12
-rw-r--r--src/tools/rustbook/src/main.rs72
2 files changed, 67 insertions, 17 deletions
diff --git a/src/tools/rustbook/Cargo.toml b/src/tools/rustbook/Cargo.toml
index 5e11646ee4c..27454431228 100644
--- a/src/tools/rustbook/Cargo.toml
+++ b/src/tools/rustbook/Cargo.toml
@@ -1,13 +1,23 @@
+cargo-features = ["rename-dependency"]
+
 [package]
 authors = ["The Rust Project Developers"]
 name = "rustbook"
 version = "0.1.0"
 license = "MIT/Apache-2.0"
+edition = "2018"
 
 [dependencies]
 clap = "2.25.0"
 
-[dependencies.mdbook]
+[dependencies.mdbook_2]
+package = "mdbook"
+version = "0.2.2"
+default-features = false
+features = ["search"]
+
+[dependencies.mdbook_1]
+package = "mdbook"
 version = "0.1.7"
 default-features = false
 features = ["search"]
diff --git a/src/tools/rustbook/src/main.rs b/src/tools/rustbook/src/main.rs
index 80a85dc2ac0..5a6246347cc 100644
--- a/src/tools/rustbook/src/main.rs
+++ b/src/tools/rustbook/src/main.rs
@@ -1,21 +1,24 @@
 //
-extern crate mdbook;
-#[macro_use]
-extern crate clap;
+use clap::{crate_version};
 
 use std::env;
 use std::path::{Path, PathBuf};
 
 use clap::{App, ArgMatches, SubCommand, AppSettings};
 
-use mdbook::MDBook;
-use mdbook::errors::Result;
+use mdbook_1::{MDBook as MDBook1};
+use mdbook_1::errors::{Result as Result1};
+
+use mdbook_2::{MDBook as MDBook2};
+use mdbook_2::errors::{Result as Result2};
 
 fn main() {
     let d_message = "-d, --dest-dir=[dest-dir]
 'The output directory for your book{n}(Defaults to ./book when omitted)'";
     let dir_message = "[dir]
 'A directory for your book{n}(Defaults to Current Directory when omitted)'";
+    let vers_message = "-m, --mdbook-vers=[md-version]
+'The version of mdbook to use for your book{n}(Defaults to 1 when omitted)'";
 
     let matches = App::new("rustbook")
                     .about("Build a book with mdBook")
@@ -25,29 +28,66 @@ fn main() {
                     .subcommand(SubCommand::with_name("build")
                         .about("Build the book from the markdown files")
                         .arg_from_usage(d_message)
-                        .arg_from_usage(dir_message))
+                        .arg_from_usage(dir_message)
+                        .arg_from_usage(vers_message))
                     .get_matches();
 
     // Check which subcomamnd the user ran...
-    let res = match matches.subcommand() {
-        ("build", Some(sub_matches)) => build(sub_matches),
+    match matches.subcommand() {
+        ("build", Some(sub_matches)) => {
+            match sub_matches.value_of("mdbook-vers") {
+                None | Some("1") => {
+                    if let Err(e) = build_1(sub_matches) {
+                        eprintln!("Error: {}", e);
+
+                        for cause in e.iter().skip(1) {
+                            eprintln!("\tCaused By: {}", cause);
+                        }
+
+                        ::std::process::exit(101);
+                    }
+                }
+                Some("2") => {
+                    if let Err(e) = build_2(sub_matches) {
+                        eprintln!("Error: {}", e);
+
+                        for cause in e.iter().skip(1) {
+                            eprintln!("\tCaused By: {}", cause);
+                        }
+
+                        ::std::process::exit(101);
+                    }
+                }
+                _ => {
+                    panic!("Invalid mdBook version! Select '1' or '2'");
+                }
+            };
+        },
         (_, _) => unreachable!(),
     };
+}
 
-    if let Err(e) = res {
-        eprintln!("Error: {}", e);
+// Build command implementation
+pub fn build_1(args: &ArgMatches) -> Result1<()> {
+    let book_dir = get_book_dir(args);
+    let mut book = MDBook1::load(&book_dir)?;
 
-        for cause in e.iter().skip(1) {
-            eprintln!("\tCaused By: {}", cause);
-        }
+    // Set this to allow us to catch bugs in advance.
+    book.config.build.create_missing = false;
 
-        ::std::process::exit(101);
+    if let Some(dest_dir) = args.value_of("dest-dir") {
+        book.config.build.build_dir = PathBuf::from(dest_dir);
     }
+
+    book.build()?;
+
+    Ok(())
 }
+
 // Build command implementation
-pub fn build(args: &ArgMatches) -> Result<()> {
+pub fn build_2(args: &ArgMatches) -> Result2<()> {
     let book_dir = get_book_dir(args);
-    let mut book = MDBook::load(&book_dir)?;
+    let mut book = MDBook2::load(&book_dir)?;
 
     // Set this to allow us to catch bugs in advance.
     book.config.build.create_missing = false;