2017-10-03 19:40:23 +08:00
|
|
|
use clap::{App, ArgMatches, SubCommand};
|
2017-06-26 07:24:33 +08:00
|
|
|
use get_book_dir;
|
2018-07-24 01:45:01 +08:00
|
|
|
use mdbook::errors::Result;
|
|
|
|
use mdbook::MDBook;
|
2017-06-26 07:24:33 +08:00
|
|
|
|
2017-06-27 13:59:50 +08:00
|
|
|
// Create clap subcommand arguments
|
|
|
|
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
2017-06-19 22:06:15 +08:00
|
|
|
SubCommand::with_name("test")
|
|
|
|
.about("Test that code samples compile")
|
2018-07-24 01:45:01 +08:00
|
|
|
.arg_from_usage("-L, --library-path [DIR]... 'directory to add to crate search path'")
|
2017-06-27 13:59:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-26 07:24:33 +08:00
|
|
|
// test command implementation
|
2017-06-27 13:59:50 +08:00
|
|
|
pub fn execute(args: &ArgMatches) -> Result<()> {
|
2017-10-03 19:40:23 +08:00
|
|
|
let library_paths: Vec<&str> = args.values_of("library-path")
|
2018-07-24 01:45:01 +08:00
|
|
|
.map(|v| v.collect())
|
|
|
|
.unwrap_or_default();
|
2017-06-26 07:24:33 +08:00
|
|
|
let book_dir = get_book_dir(args);
|
2017-11-18 20:41:04 +08:00
|
|
|
let mut book = MDBook::load(&book_dir)?;
|
2017-06-26 07:24:33 +08:00
|
|
|
|
2017-06-19 22:06:15 +08:00
|
|
|
book.test(library_paths)?;
|
2017-06-26 07:24:33 +08:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|