Fixed `mdbook build` overwriting your book with the `mdbook init` stuff
This commit is contained in:
parent
1bd26fb2ee
commit
2bdca9e720
|
@ -17,7 +17,7 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||||
// Build command implementation
|
// Build command implementation
|
||||||
pub fn execute(args: &ArgMatches) -> Result<()> {
|
pub fn execute(args: &ArgMatches) -> Result<()> {
|
||||||
let book_dir = get_book_dir(args);
|
let book_dir = get_book_dir(args);
|
||||||
let book = MDBook::new(&book_dir).read_config()?;
|
let book = MDBook::new(&book_dir);
|
||||||
|
|
||||||
let mut book = match args.value_of("dest-dir") {
|
let mut book = match args.value_of("dest-dir") {
|
||||||
Some(dest_dir) => book.with_destination(dest_dir),
|
Some(dest_dir) => book.with_destination(dest_dir),
|
||||||
|
@ -30,6 +30,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
|
||||||
book = book.with_curly_quotes(true);
|
book = book.with_curly_quotes(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
book = book.read_config()?;
|
||||||
book.build()?;
|
book.build()?;
|
||||||
|
|
||||||
if args.is_present("open") {
|
if args.is_present("open") {
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl MDBook {
|
||||||
renderer: Box::new(HtmlHandlebars::new()),
|
renderer: Box::new(HtmlHandlebars::new()),
|
||||||
|
|
||||||
livereload: None,
|
livereload: None,
|
||||||
create_missing: true,
|
create_missing: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,15 +175,18 @@ impl MDBook {
|
||||||
let src = self.config.get_source();
|
let src = self.config.get_source();
|
||||||
let summary = src.join("SUMMARY.md");
|
let summary = src.join("SUMMARY.md");
|
||||||
|
|
||||||
if summary.exists() && self.create_missing {
|
if summary.exists() {
|
||||||
|
if self.create_missing {
|
||||||
// As a special case, if we run "mdbook init" on a book which
|
// As a special case, if we run "mdbook init" on a book which
|
||||||
// already has a summary we'll read that summary and create
|
// already has a summary we'll read that summary and create
|
||||||
// stubs for any files which don't already exist (@azerupi likes
|
// stubs for any files which don't already exist (@azerupi likes
|
||||||
// having access to this shortcut).
|
// having access to this shortcut).
|
||||||
return create_files_from_summary(&src, &summary);
|
return create_files_from_summary(&src, &summary);
|
||||||
|
} else {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to create the summary file
|
|
||||||
debug!("[*]: Creating SUMMARY.md");
|
debug!("[*]: Creating SUMMARY.md");
|
||||||
let mut f = File::create(&summary)?;
|
let mut f = File::create(&summary)?;
|
||||||
writeln!(f, "{}", STUB_SUMMARY_CONTENTS)?;
|
writeln!(f, "{}", STUB_SUMMARY_CONTENTS)?;
|
||||||
|
|
Loading…
Reference in New Issue