@@ -13,13 +13,13 @@ extern crate mdbook;
1313extern crate clap;
1414
1515use std:: env;
16- use std:: error:: Error ;
1716use std:: io:: { self , Write } ;
1817use std:: path:: { Path , PathBuf } ;
1918
2019use clap:: { App , ArgMatches , SubCommand , AppSettings } ;
2120
2221use mdbook:: MDBook ;
22+ use mdbook:: errors:: Result ;
2323
2424fn main ( ) {
2525 let d_message = "-d, --dest-dir=[dest-dir]
@@ -49,34 +49,21 @@ fn main() {
4949 :: std:: process:: exit ( 101 ) ;
5050 }
5151}
52-
5352// Build command implementation
54- fn build ( args : & ArgMatches ) -> Result < ( ) , Box < Error > > {
55- let book = build_mdbook_struct ( args) ;
53+ pub fn build ( args : & ArgMatches ) -> Result < ( ) > {
54+ let book_dir = get_book_dir ( args) ;
55+ let book = MDBook :: new ( & book_dir) . read_config ( ) ?;
5656
5757 let mut book = match args. value_of ( "dest-dir" ) {
58- Some ( dest_dir) => book. set_dest ( Path :: new ( dest_dir) ) ,
59- None => book
58+ Some ( dest_dir) => book. with_destination ( dest_dir) ,
59+ None => book,
6060 } ;
6161
62- try! ( book. build ( ) ) ;
62+ book. build ( ) ? ;
6363
6464 Ok ( ( ) )
6565}
6666
67- fn build_mdbook_struct ( args : & ArgMatches ) -> mdbook:: MDBook {
68- let book_dir = get_book_dir ( args) ;
69- let mut book = MDBook :: new ( & book_dir) . read_config ( ) ;
70-
71- // By default mdbook will attempt to create non-existent files referenced
72- // from SUMMARY.md files. This is problematic on CI where we mount the
73- // source directory as readonly. To avoid any issues, we'll disabled
74- // mdbook's implicit file creation feature.
75- book. create_missing = false ;
76-
77- book
78- }
79-
8067fn get_book_dir ( args : & ArgMatches ) -> PathBuf {
8168 if let Some ( dir) = args. value_of ( "dir" ) {
8269 // Check if path is relative from current dir, or absolute...
0 commit comments