]> git.proxmox.com Git - rustc.git/blob - src/vendor/mdbook/src/bin/clean.rs
New upstream version 1.27.1+dfsg1
[rustc.git] / src / vendor / mdbook / src / bin / clean.rs
1 use std::fs;
2 use std::path::PathBuf;
3 use clap::{App, ArgMatches, SubCommand};
4 use mdbook::MDBook;
5 use mdbook::errors::*;
6 use get_book_dir;
7
8 // Create clap subcommand arguments
9 pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
10 SubCommand::with_name("clean")
11 .about("Delete built book")
12 .arg_from_usage(
13 "-d, --dest-dir=[dest-dir] 'The directory of built book{n}(Defaults to ./book when \
14 omitted)'",
15 )
16 }
17
18 // Clean command implementation
19 pub fn execute(args: &ArgMatches) -> ::mdbook::errors::Result<()> {
20 let book_dir = get_book_dir(args);
21 let book = MDBook::load(&book_dir)?;
22
23 let dir_to_remove = match args.value_of("dest-dir") {
24 Some(dest_dir) => PathBuf::from(dest_dir),
25 None => book.root.join(&book.config.build.build_dir),
26 };
27 fs::remove_dir_all(&dir_to_remove).chain_err(|| "Unable to remove the build directory")?;
28
29 Ok(())
30 }