2 use std
::path
::PathBuf
;
3 use clap
::{App, ArgMatches, SubCommand}
;
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")
13 "-d, --dest-dir=[dest-dir] 'The directory of built book{n}(Defaults to ./book when \
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
)?
;
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
),
27 fs
::remove_dir_all(&dir_to_remove
).chain_err(|| "Unable to remove the build directory")?
;