@@ -31,6 +31,20 @@ fn main() {
31
31
(Defaults to the current directory when omitted)")
32
32
. value_parser ( clap:: value_parser!( PathBuf ) ) ;
33
33
34
+ // Note: we don't parse this into a `PathBuf` because it is comma separated
35
+ // strings *and* we will ultimately pass it into `MDBook::test()`, which
36
+ // accepts `Vec<&str>`. Although it is a bit annoying that `-l/--lang` and
37
+ // `-L/--library-path` are so close, this is the same set of arguments we
38
+ // would pass when invoking mdbook on the CLI, so making them match when
39
+ // invoking rustbook makes for good consistency.
40
+ let library_path_arg = arg ! (
41
+ -L --"library-path" <PATHS >
42
+ "A comma-separated list of directories to add to the crate search\n \
43
+ path when building tests"
44
+ )
45
+ . required ( false )
46
+ . value_parser ( parse_library_paths) ;
47
+
34
48
let matches = Command :: new ( "rustbook" )
35
49
. about ( "Build a book with mdBook" )
36
50
. author ( "Steve Klabnik <[email protected] >" )
@@ -48,7 +62,8 @@ fn main() {
48
62
. subcommand (
49
63
Command :: new ( "test" )
50
64
. about ( "Tests that a book's Rust code samples compile" )
51
- . arg ( dir_arg) ,
65
+ . arg ( dir_arg)
66
+ . arg ( library_path_arg) ,
52
67
)
53
68
. get_matches ( ) ;
54
69
@@ -113,8 +128,12 @@ pub fn build(args: &ArgMatches) -> Result3<()> {
113
128
114
129
fn test ( args : & ArgMatches ) -> Result3 < ( ) > {
115
130
let book_dir = get_book_dir ( args) ;
131
+ let library_paths = args
132
+ . try_get_one :: < Vec < String > > ( "library-path" ) ?
133
+ . map ( |v| v. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < & str > > ( ) )
134
+ . unwrap_or_default ( ) ;
116
135
let mut book = load_book ( & book_dir) ?;
117
- book. test ( vec ! [ ] )
136
+ book. test ( library_paths )
118
137
}
119
138
120
139
fn get_book_dir ( args : & ArgMatches ) -> PathBuf {
@@ -132,12 +151,16 @@ fn load_book(book_dir: &Path) -> Result3<MDBook> {
132
151
Ok ( book)
133
152
}
134
153
154
+ fn parse_library_paths ( input : & str ) -> Result < Vec < String > , String > {
155
+ Ok ( input. split ( "," ) . map ( String :: from) . collect ( ) )
156
+ }
157
+
135
158
fn handle_error ( error : mdbook:: errors:: Error ) -> ! {
136
159
eprintln ! ( "Error: {}" , error) ;
137
160
138
161
for cause in error. chain ( ) . skip ( 1 ) {
139
162
eprintln ! ( "\t Caused By: {}" , cause) ;
140
163
}
141
164
142
- :: std:: process:: exit ( 101 ) ;
165
+ std:: process:: exit ( 101 ) ;
143
166
}
0 commit comments