2017-10-03 19:40:23 +08:00
|
|
|
use clap::{App, ArgMatches, SubCommand};
|
2017-06-26 07:24:33 +08:00
|
|
|
use mdbook::MDBook;
|
2017-06-27 05:17:46 +08:00
|
|
|
use mdbook::errors::Result;
|
2017-06-26 07:24:33 +08:00
|
|
|
use get_book_dir;
|
|
|
|
|
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")
|
2017-10-03 19:40:23 +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")
|
|
|
|
.map(|v| v.collect())
|
|
|
|
.unwrap_or_default();
|
2017-06-26 07:24:33 +08:00
|
|
|
let book_dir = get_book_dir(args);
|
|
|
|
let mut book = MDBook::new(&book_dir).read_config()?;
|
|
|
|
|
2017-06-19 22:06:15 +08:00
|
|
|
book.test(library_paths)?;
|
2017-06-26 07:24:33 +08:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|