From 4b31ae67898217a47948be9df3e4e6b0146248e7 Mon Sep 17 00:00:00 2001 From: Pete Hayes Date: Thu, 12 Jan 2017 12:26:22 +0000 Subject: [PATCH] Add --dest-dir arg to build, watch and serve subcommands --- src/bin/mdbook.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/bin/mdbook.rs b/src/bin/mdbook.rs index a2e7bef3..29f6d806 100644 --- a/src/bin/mdbook.rs +++ b/src/bin/mdbook.rs @@ -64,14 +64,17 @@ fn main() { .subcommand(SubCommand::with_name("build") .about("Build the book from the markdown files") .arg_from_usage("-o, --open 'Open the compiled book in a web browser'") + .arg_from_usage("-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'") .arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'")) .subcommand(SubCommand::with_name("watch") .about("Watch the files for changes") .arg_from_usage("-o, --open 'Open the compiled book in a web browser'") + .arg_from_usage("-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'") .arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'")) .subcommand(SubCommand::with_name("serve") .about("Serve the book at http://localhost:3000. Rebuild and reload on change.") .arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'") + .arg_from_usage("-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'") .arg_from_usage("-p, --port=[port] 'Use another port{n}(Defaults to 3000)'") .arg_from_usage("-w, --websocket-port=[ws-port] 'Use another port for the websocket connection (livereload){n}(Defaults to 3001)'") .arg_from_usage("-i, --interface=[interface] 'Interface to listen on{n}(Defaults to localhost)'") @@ -166,7 +169,12 @@ fn init(args: &ArgMatches) -> Result<(), Box> { // Build command implementation fn build(args: &ArgMatches) -> Result<(), Box> { let book_dir = get_book_dir(args); - let mut book = MDBook::new(&book_dir).read_config(); + let book = MDBook::new(&book_dir).read_config(); + + let mut book = match args.value_of("dest-dir") { + Some(dest_dir) => book.set_dest(Path::new(dest_dir)), + None => book + }; try!(book.build()); @@ -182,7 +190,12 @@ fn build(args: &ArgMatches) -> Result<(), Box> { #[cfg(feature = "watch")] fn watch(args: &ArgMatches) -> Result<(), Box> { let book_dir = get_book_dir(args); - let mut book = MDBook::new(&book_dir).read_config(); + let book = MDBook::new(&book_dir).read_config(); + + let mut book = match args.value_of("dest-dir") { + Some(dest_dir) => book.set_dest(Path::new(dest_dir)), + None => book + }; if args.is_present("open") { try!(book.build()); @@ -208,7 +221,13 @@ fn serve(args: &ArgMatches) -> Result<(), Box> { const RELOAD_COMMAND: &'static str = "reload"; let book_dir = get_book_dir(args); - let mut book = MDBook::new(&book_dir).read_config(); + let book = MDBook::new(&book_dir).read_config(); + + let mut book = match args.value_of("dest-dir") { + Some(dest_dir) => book.set_dest(Path::new(dest_dir)), + None => book + }; + let port = args.value_of("port").unwrap_or("3000"); let ws_port = args.value_of("ws-port").unwrap_or("3001"); let interface = args.value_of("interface").unwrap_or("localhost");