@@ -58,20 +58,23 @@ fn main() {
58
58
. subcommand ( SubCommand :: with_name ( "init" )
59
59
. about ( "Create boilerplate structure and files in the directory" )
60
60
// the {n} denotes a newline which will properly aligned in all help messages
61
- . arg_from_usage ( "[dir] 'A directory for your book{n}(Defaults to Current Directory when ommitted )'" )
61
+ . arg_from_usage ( "[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted )'" )
62
62
. arg_from_usage ( "--theme 'Copies the default theme into your source folder'" )
63
63
. arg_from_usage ( "--force 'skip confirmation prompts'" ) )
64
64
. subcommand ( SubCommand :: with_name ( "build" )
65
65
. about ( "Build the book from the markdown files" )
66
66
. arg_from_usage ( "-o, --open 'Open the compiled book in a web browser'" )
67
- . arg_from_usage ( "[dir] 'A directory for your book{n}(Defaults to Current Directory when ommitted)'" ) )
67
+ . arg_from_usage ( "-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'" )
68
+ . arg_from_usage ( "[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'" ) )
68
69
. subcommand ( SubCommand :: with_name ( "watch" )
69
70
. about ( "Watch the files for changes" )
70
71
. arg_from_usage ( "-o, --open 'Open the compiled book in a web browser'" )
71
- . arg_from_usage ( "[dir] 'A directory for your book{n}(Defaults to Current Directory when ommitted)'" ) )
72
+ . arg_from_usage ( "-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'" )
73
+ . arg_from_usage ( "[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'" ) )
72
74
. subcommand ( SubCommand :: with_name ( "serve" )
73
75
. about ( "Serve the book at http://localhost:3000. Rebuild and reload on change." )
74
- . arg_from_usage ( "[dir] 'A directory for your book{n}(Defaults to Current Directory when ommitted)'" )
76
+ . arg_from_usage ( "[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'" )
77
+ . arg_from_usage ( "-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'" )
75
78
. arg_from_usage ( "-p, --port=[port] 'Use another port{n}(Defaults to 3000)'" )
76
79
. arg_from_usage ( "-w, --websocket-port=[ws-port] 'Use another port for the websocket connection (livereload){n}(Defaults to 3001)'" )
77
80
. arg_from_usage ( "-i, --interface=[interface] 'Interface to listen on{n}(Defaults to localhost)'" )
@@ -166,7 +169,12 @@ fn init(args: &ArgMatches) -> Result<(), Box<Error>> {
166
169
// Build command implementation
167
170
fn build ( args : & ArgMatches ) -> Result < ( ) , Box < Error > > {
168
171
let book_dir = get_book_dir ( args) ;
169
- let mut book = MDBook :: new ( & book_dir) . read_config ( ) ;
172
+ let book = MDBook :: new ( & book_dir) . read_config ( ) ;
173
+
174
+ let mut book = match args. value_of ( "dest-dir" ) {
175
+ Some ( dest_dir) => book. set_dest ( Path :: new ( dest_dir) ) ,
176
+ None => book
177
+ } ;
170
178
171
179
try!( book. build ( ) ) ;
172
180
@@ -182,7 +190,12 @@ fn build(args: &ArgMatches) -> Result<(), Box<Error>> {
182
190
#[ cfg( feature = "watch" ) ]
183
191
fn watch ( args : & ArgMatches ) -> Result < ( ) , Box < Error > > {
184
192
let book_dir = get_book_dir ( args) ;
185
- let mut book = MDBook :: new ( & book_dir) . read_config ( ) ;
193
+ let book = MDBook :: new ( & book_dir) . read_config ( ) ;
194
+
195
+ let mut book = match args. value_of ( "dest-dir" ) {
196
+ Some ( dest_dir) => book. set_dest ( Path :: new ( dest_dir) ) ,
197
+ None => book
198
+ } ;
186
199
187
200
if args. is_present ( "open" ) {
188
201
try!( book. build ( ) ) ;
@@ -208,7 +221,13 @@ fn serve(args: &ArgMatches) -> Result<(), Box<Error>> {
208
221
const RELOAD_COMMAND : & ' static str = "reload" ;
209
222
210
223
let book_dir = get_book_dir ( args) ;
211
- let mut book = MDBook :: new ( & book_dir) . read_config ( ) ;
224
+ let book = MDBook :: new ( & book_dir) . read_config ( ) ;
225
+
226
+ let mut book = match args. value_of ( "dest-dir" ) {
227
+ Some ( dest_dir) => book. set_dest ( Path :: new ( dest_dir) ) ,
228
+ None => book
229
+ } ;
230
+
212
231
let port = args. value_of ( "port" ) . unwrap_or ( "3000" ) ;
213
232
let ws_port = args. value_of ( "ws-port" ) . unwrap_or ( "3001" ) ;
214
233
let interface = args. value_of ( "interface" ) . unwrap_or ( "localhost" ) ;
0 commit comments