Skip to content

Commit 0d6185a

Browse files
authored
Merge pull request #199 from petehayes102/master
Add --dest-dir option to build, watch and serve subcommands
2 parents 3a71371 + 4b31ae6 commit 0d6185a

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/bin/mdbook.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,23 @@ fn main() {
5858
.subcommand(SubCommand::with_name("init")
5959
.about("Create boilerplate structure and files in the directory")
6060
// 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)'")
6262
.arg_from_usage("--theme 'Copies the default theme into your source folder'")
6363
.arg_from_usage("--force 'skip confirmation prompts'"))
6464
.subcommand(SubCommand::with_name("build")
6565
.about("Build the book from the markdown files")
6666
.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)'"))
6869
.subcommand(SubCommand::with_name("watch")
6970
.about("Watch the files for changes")
7071
.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)'"))
7274
.subcommand(SubCommand::with_name("serve")
7375
.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)'")
7578
.arg_from_usage("-p, --port=[port] 'Use another port{n}(Defaults to 3000)'")
7679
.arg_from_usage("-w, --websocket-port=[ws-port] 'Use another port for the websocket connection (livereload){n}(Defaults to 3001)'")
7780
.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>> {
166169
// Build command implementation
167170
fn build(args: &ArgMatches) -> Result<(), Box<Error>> {
168171
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+
};
170178

171179
try!(book.build());
172180

@@ -182,7 +190,12 @@ fn build(args: &ArgMatches) -> Result<(), Box<Error>> {
182190
#[cfg(feature = "watch")]
183191
fn watch(args: &ArgMatches) -> Result<(), Box<Error>> {
184192
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+
};
186199

187200
if args.is_present("open") {
188201
try!(book.build());
@@ -208,7 +221,13 @@ fn serve(args: &ArgMatches) -> Result<(), Box<Error>> {
208221
const RELOAD_COMMAND: &'static str = "reload";
209222

210223
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+
212231
let port = args.value_of("port").unwrap_or("3000");
213232
let ws_port = args.value_of("ws-port").unwrap_or("3001");
214233
let interface = args.value_of("interface").unwrap_or("localhost");

0 commit comments

Comments
 (0)