@@ -29,6 +29,7 @@ pub fn make_subcommand<'help>() -> App<'help> {
29
29
(Defaults to the Current Directory when omitted)"
30
30
) )
31
31
. arg ( arg ! ( -o --open "Opens the compiled book in a web browser" ) )
32
+ . arg ( arg ! ( --"extra-watch-dirs" <dirs> "Extra directories to watch, comma separated" ) )
32
33
}
33
34
34
35
// Watch command implementation
@@ -53,7 +54,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
53
54
open ( path) ;
54
55
}
55
56
56
- trigger_on_change ( & book, |paths, book_dir| {
57
+ let extra_dirs = parse_extra_dirs ( args. value_of ( "extra-watch-dirs" ) ) ?;
58
+ trigger_on_change ( & book, & extra_dirs, |paths, book_dir| {
57
59
info ! ( "Files changed: {:?}\n Building book...\n " , paths) ;
58
60
let result = MDBook :: load ( & book_dir) . and_then ( |mut b| {
59
61
update_config ( & mut b) ;
@@ -116,8 +118,19 @@ fn filter_ignored_files(exclusion_checker: gitignore::File, paths: &[PathBuf]) -
116
118
. collect ( )
117
119
}
118
120
121
+ /// Turn comma-separated list of directories into a Vec<PathBuf>
122
+ pub fn parse_extra_dirs ( dirs : Option < & str > ) -> Result < Vec < PathBuf > > {
123
+ match dirs {
124
+ Some ( dirs) => dirs
125
+ . split ( "," )
126
+ . map ( |s| Ok ( PathBuf :: from ( s) . canonicalize ( ) ?) )
127
+ . collect :: < Result < Vec < _ > > > ( ) ,
128
+ None => Ok ( Vec :: new ( ) ) ,
129
+ }
130
+ }
131
+
119
132
/// Calls the closure when a book source file is changed, blocking indefinitely.
120
- pub fn trigger_on_change < F > ( book : & MDBook , closure : F )
133
+ pub fn trigger_on_change < F > ( book : & MDBook , extra_dirs : & [ PathBuf ] , closure : F )
121
134
where
122
135
F : Fn ( Vec < PathBuf > , & Path ) ,
123
136
{
@@ -146,6 +159,10 @@ where
146
159
// Add the book.toml file to the watcher if it exists
147
160
let _ = watcher. watch ( book. root . join ( "book.toml" ) , NonRecursive ) ;
148
161
162
+ for dir in extra_dirs {
163
+ let _ = watcher. watch ( dir, Recursive ) ;
164
+ }
165
+
149
166
info ! ( "Listening for changes..." ) ;
150
167
151
168
loop {
0 commit comments