mdbook/src/cmd/build.rs
Eric Huss c177081104 Change CLI dest-dir to be relative to the current directory
This changes the `--dest-dir` flag so that it is relative to the current
directory, not the book root. This has been a source of confusion for
several people.

Fixes https://github.com/rust-lang/mdBook/issues/698
2025-08-18 16:28:08 -07:00

35 lines
902 B
Rust

use super::command_prelude::*;
use crate::{get_book_dir, open};
use anyhow::Result;
use mdbook_driver::MDBook;
// Create clap subcommand arguments
pub fn make_subcommand() -> Command {
Command::new("build")
.about("Builds a book from its markdown files")
.arg_dest_dir()
.arg_root_dir()
.arg_open()
}
// Build command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let book_dir = get_book_dir(args);
let mut book = MDBook::load(book_dir)?;
set_dest_dir(args, &mut book);
book.build()?;
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)
}
open(path);
}
Ok(())
}