mdbook/src/cmd/build.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
902 B
Rust
Raw Normal View History

2022-07-04 23:16:31 +08:00
use super::command_prelude::*;
use crate::{get_book_dir, open};
use anyhow::Result;
2025-07-21 21:42:58 -07:00
use mdbook_driver::MDBook;
// Create clap subcommand arguments
2022-07-04 23:16:31 +08:00
pub fn make_subcommand() -> Command {
Command::new("build")
2018-08-02 15:48:22 -05:00
.about("Builds a book from its markdown files")
2022-07-04 23:16:31 +08:00
.arg_dest_dir()
.arg_root_dir()
.arg_open()
}
// Build command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let book_dir = get_book_dir(args);
2023-05-13 09:44:11 -07:00
let mut book = MDBook::load(book_dir)?;
set_dest_dir(args, &mut book);
book.build()?;
2022-07-04 23:16:31 +08:00
if args.get_flag("open") {
// FIXME: What's the right behaviour if we don't use the HTML renderer?
let path = book.build_dir_for("html").join("index.html");
if !path.exists() {
error!("No chapter available to open");
std::process::exit(1)
2021-12-28 21:00:06 -08:00
}
open(path);
}
Ok(())
}