From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/mdbook/src/cmd/build.rs | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 vendor/mdbook/src/cmd/build.rs (limited to 'vendor/mdbook/src/cmd/build.rs') diff --git a/vendor/mdbook/src/cmd/build.rs b/vendor/mdbook/src/cmd/build.rs new file mode 100644 index 000000000..5fe73236c --- /dev/null +++ b/vendor/mdbook/src/cmd/build.rs @@ -0,0 +1,50 @@ +use crate::{get_book_dir, open}; +use clap::{arg, App, Arg, ArgMatches}; +use mdbook::errors::Result; +use mdbook::MDBook; + +// Create clap subcommand arguments +pub fn make_subcommand<'help>() -> App<'help> { + App::new("build") + .about("Builds a book from its markdown files") + .arg( + Arg::new("dest-dir") + .short('d') + .long("dest-dir") + .value_name("dest-dir") + .help( + "Output directory for the book{n}\ + Relative paths are interpreted relative to the book's root directory.{n}\ + If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.", + ), + ) + .arg(arg!([dir] + "Root directory for the book{n}\ + (Defaults to the Current Directory when omitted)" + )) + .arg(arg!(-o --open "Opens the compiled book in a web browser")) +} + +// Build command implementation +pub fn execute(args: &ArgMatches) -> Result<()> { + let book_dir = get_book_dir(args); + let mut book = MDBook::load(&book_dir)?; + + if let Some(dest_dir) = args.value_of("dest-dir") { + book.config.build.build_dir = dest_dir.into(); + } + + book.build()?; + + if args.is_present("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(()) +} -- cgit v1.2.3