Updated the binary to use the new signature
This commit is contained in:
parent
65a60bf81f
commit
ed83e0ec10
|
@ -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),
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -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#"
|
||||
<script type="text/javascript">
|
||||
var socket = new WebSocket("ws://{}:{}");
|
||||
socket.onmessage = function (event) {{
|
||||
|
@ -70,7 +71,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
|
|||
"#,
|
||||
public_address,
|
||||
ws_port,
|
||||
RELOAD_COMMAND));
|
||||
RELOAD_COMMAND
|
||||
));
|
||||
|
||||
book.build()?;
|
||||
|
||||
|
|
|
@ -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)?;
|
||||
|
||||
|
|
|
@ -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<F>(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<F>(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() {
|
||||
.is_err()
|
||||
{
|
||||
// do nothing if book.json is not found
|
||||
}
|
||||
if watcher
|
||||
.watch(book.get_root().join("book.toml"), NonRecursive)
|
||||
.is_err() {
|
||||
.is_err()
|
||||
{
|
||||
// do nothing if book.toml is not found
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue