From ed83e0ec102f4bb116defb4ae2c0493098047aa8 Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Sat, 8 Jul 2017 20:25:59 +0800 Subject: [PATCH] Updated the binary to use the new signature --- src/bin/build.rs | 2 +- src/bin/init.rs | 5 +---- src/bin/serve.rs | 12 +++++++----- src/bin/test.rs | 2 +- src/bin/watch.rs | 19 ++++++++++++------- tests/config.rs | 11 +++++++---- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/bin/build.rs b/src/bin/build.rs index 1a296ee5..5b681a2b 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -17,7 +17,7 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { // Build command implementation pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let book = MDBook::new(&book_dir).read_config()?; + let book = MDBook::new(&book_dir)?.read_config()?; let mut book = match args.value_of("dest-dir") { Some(dest_dir) => book.with_destination(dest_dir), diff --git a/src/bin/init.rs b/src/bin/init.rs index 37277fc7..d2118d29 100644 --- a/src/bin/init.rs +++ b/src/bin/init.rs @@ -19,10 +19,7 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let mut book = MDBook::new(&book_dir); - - // Call the function that does the initialization - book.init()?; + let book = MDBook::init(&book_dir)?; // If flag `--theme` is present, copy theme to src if args.is_present("theme") { diff --git a/src/bin/serve.rs b/src/bin/serve.rs index 54c0a248..0a1d0979 100644 --- a/src/bin/serve.rs +++ b/src/bin/serve.rs @@ -33,7 +33,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { const RELOAD_COMMAND: &'static str = "reload"; let book_dir = get_book_dir(args); - let book = MDBook::new(&book_dir).read_config()?; + let book = MDBook::new(&book_dir)?.read_config()?; let mut book = match args.value_of("dest-dir") { Some(dest_dir) => book.with_destination(Path::new(dest_dir)), @@ -53,7 +53,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> { let address = format!("{}:{}", interface, port); let ws_address = format!("{}:{}", interface, ws_port); - book.set_livereload(format!(r#" + book.set_livereload(format!( + r#" "#, - public_address, - ws_port, - RELOAD_COMMAND)); + public_address, + ws_port, + RELOAD_COMMAND + )); book.build()?; diff --git a/src/bin/test.rs b/src/bin/test.rs index ad82d316..b56d3df5 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -14,7 +14,7 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { pub fn execute(args: &ArgMatches) -> Result<()> { let library_paths: Vec<&str> = args.values_of("library-path").map(|v| v.collect()).unwrap_or_default(); let book_dir = get_book_dir(args); - let mut book = MDBook::new(&book_dir).read_config()?; + let mut book = MDBook::new(&book_dir)?.read_config()?; book.test(library_paths)?; diff --git a/src/bin/watch.rs b/src/bin/watch.rs index 0b65d8d0..e2601350 100644 --- a/src/bin/watch.rs +++ b/src/bin/watch.rs @@ -24,7 +24,7 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { // Watch command implementation pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let book = MDBook::new(&book_dir).read_config()?; + let book = MDBook::new(&book_dir)?.read_config()?; let mut book = match args.value_of("dest-dir") { Some(dest_dir) => book.with_destination(dest_dir), @@ -53,7 +53,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> { // Calls the closure when a book source file is changed. This is blocking! pub fn trigger_on_change(book: &mut MDBook, closure: F) -> () - where F: Fn(&Path, &mut MDBook) -> () +where + F: Fn(&Path, &mut MDBook) -> (), { use self::notify::RecursiveMode::*; use self::notify::DebouncedEvent::*; @@ -76,19 +77,23 @@ pub fn trigger_on_change(book: &mut MDBook, closure: F) -> () }; // Add the theme directory to the watcher - watcher.watch(book.get_theme_path(), Recursive).unwrap_or_default(); + watcher + .watch(book.get_theme_path(), Recursive) + .unwrap_or_default(); // Add the book.{json,toml} file to the watcher if it exists, because it's not // located in the source directory if watcher - .watch(book.get_root().join("book.json"), NonRecursive) - .is_err() { + .watch(book.get_root().join("book.json"), NonRecursive) + .is_err() + { // do nothing if book.json is not found } if watcher - .watch(book.get_root().join("book.toml"), NonRecursive) - .is_err() { + .watch(book.get_root().join("book.toml"), NonRecursive) + .is_err() + { // do nothing if book.toml is not found } diff --git a/tests/config.rs b/tests/config.rs index 6601ef39..0e4a9635 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -7,13 +7,15 @@ use std::io::Write; use mdbook::MDBook; use tempdir::TempDir; -// Tests that config values unspecified in the configuration file do not overwrite +// Tests that config values unspecified in the configuration file do not +// overwrite // values specified earlier. #[test] fn do_not_overwrite_unspecified_config_values() { let dir = TempDir::new("mdbook").expect("Could not create a temp dir"); - let book = MDBook::new(dir.path()) + let book = MDBook::init(dir.path()) + .unwrap() .with_source("bar") .with_destination("baz") .with_mathjax_support(true); @@ -33,7 +35,9 @@ fn do_not_overwrite_unspecified_config_values() { // Try with a partial config file let file_path = dir.path().join("book.toml"); let mut f = File::create(file_path).expect("Could not create config file"); - f.write_all(br#"source = "barbaz""#).expect("Could not write to config file"); + f.write_all(br#"source = "barbaz""#).expect( + "Could not write to config file", + ); f.sync_all().expect("Could not sync the file"); let book = book.read_config().expect("Error reading the config file"); @@ -43,4 +47,3 @@ fn do_not_overwrite_unspecified_config_values() { assert_eq!(book.get_destination(), dir.path().join("baz")); assert_eq!(book.get_mathjax_support(), true); } -