call first_chapter

This commit is contained in:
josh rotenberg 2022-05-10 11:17:20 -07:00
parent 5d65967448
commit 29c729fd23
1 changed files with 9 additions and 7 deletions

View File

@ -1,4 +1,4 @@
use crate::{get_book_dir, open}; use crate::{first_chapter, get_book_dir, open};
use clap::{arg, App, Arg, ArgMatches}; use clap::{arg, App, Arg, ArgMatches};
use mdbook::errors::Result; use mdbook::errors::Result;
use mdbook::MDBook; use mdbook::MDBook;
@ -39,13 +39,15 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
if args.is_present("open") { if args.is_present("open") {
// FIXME: What's the right behaviour if we don't use the HTML renderer? // FIXME: What's the right behaviour if we don't use the HTML renderer?
let path = book.build_dir_for("html").join("index.html"); match first_chapter(&book)
if !Path::new(&path).exists() { .map(|path| book.build_dir_for("html").join(path).with_extension("html"))
error!("Need a more descriptive error here: {:?}", path); {
std::process::exit(1); Some(path) if Path::new(&path).exists() => open(path),
_ => {
error!("No chapter available to open");
std::process::exit(1)
}
} }
open(book.build_dir_for("html").join("index.html"));
} }
Ok(()) Ok(())