diff --git a/src/bookconfig.rs b/src/bookconfig.rs deleted file mode 100644 index 302fbf08..00000000 --- a/src/bookconfig.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::path::PathBuf; - -pub struct BookConfig { - dest: PathBuf, - src: PathBuf, - multilingual: bool, -} - - -impl BookConfig { - pub fn new() -> Self { - BookConfig { - dest: PathBuf::from("book"), - src: PathBuf::from("src"), - multilingual: false, - } - } - - pub fn dest(&self) -> PathBuf { - self.dest.clone() - } - - pub fn set_dest(&mut self, dest: PathBuf) { - - // dest has to be relative to the path in MDBook, - // we check if the path is relative, otherwhise we truncate - if dest.is_relative() { - self.dest = dest - } else { - self.dest = PathBuf::from(dest.file_name().unwrap()) - } - } - - pub fn src(&self) -> PathBuf { - self.src.clone() - } - - pub fn set_src(&mut self, src: PathBuf) { - - // src has to be relative to the path in MDBook, - // we check if the path is relative, otherwhise we truncate - if src.is_relative() { - self.src = src - } else { - self.src = PathBuf::from(src.file_name().unwrap()) - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 667fd136..2bdfccc4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -pub mod mdbook; -mod bookconfig; +mod mdbook; -pub use mdbook::MDBook; +pub use mdbook::mdbook::MDBook; diff --git a/src/main.rs b/src/main.rs index 9be7e1f6..7aae7f86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,7 +40,6 @@ fn main() { None => no_subcommand(args), Some(command) => (command.exec)(args), } - } @@ -64,7 +63,7 @@ fn no_subcommand(args: Vec) { if matches.opt_present("version") { println!("{} {}", NAME, VERSION); } else { - if !matches.opt_present("version"){ + if !matches.opt_present("version") && args.len() > 0 { print!("Try again, `{0}", NAME); for index in 1..args.len() { print!(" {}", args[index]); @@ -88,7 +87,6 @@ fn help(usage: &String) { } println!(""); println!("For more information about a specific command, try `mdbook --help`"); - } fn init(args: Vec) { @@ -123,7 +121,6 @@ fn init(args: Vec) { if let Err(e) = book.init() { println!("Error: {}", e); } - } fn build(args: Vec) { diff --git a/src/mdbook/bookconfig.rs b/src/mdbook/bookconfig.rs new file mode 100644 index 00000000..c30951a3 --- /dev/null +++ b/src/mdbook/bookconfig.rs @@ -0,0 +1,36 @@ +use std::path::PathBuf; + +pub struct BookConfig { + dest: PathBuf, + src: PathBuf, + multilingual: bool, +} + + +impl BookConfig { + pub fn new() -> Self { + BookConfig { + dest: PathBuf::from("book"), + src: PathBuf::from("src"), + multilingual: false, + } + } + + pub fn dest(&self) -> PathBuf { + self.dest.clone() + } + + pub fn set_dest(mut self, dest: PathBuf) -> Self { + self.dest = dest; + self + } + + pub fn src(&self) -> PathBuf { + self.src.clone() + } + + pub fn set_src(mut self, src: PathBuf) -> Self { + self.src = src; + self + } +} diff --git a/src/mdbook.rs b/src/mdbook/mdbook.rs similarity index 85% rename from src/mdbook.rs rename to src/mdbook/mdbook.rs index d01e4520..d0721bd2 100644 --- a/src/mdbook.rs +++ b/src/mdbook/mdbook.rs @@ -1,12 +1,11 @@ use std::path::PathBuf; use std::fs::{self, File, metadata}; use std::io::Write; -use std::io::{Error, ErrorKind}; +use std::io::Error; -use bookconfig::BookConfig; +use mdbook::bookconfig::BookConfig; pub struct MDBook { - path: PathBuf, config: BookConfig, } @@ -25,18 +24,16 @@ impl MDBook { } MDBook { - path: path.to_owned(), - config: BookConfig::new(), + config: BookConfig::new() + .set_src(path.join("src")) + .set_dest(path.join("book")), } } pub fn init(&self) -> Result<(), Error> { - // Logic problem: When self.dest is absolute, the directory given - // as parameter is never used... - let dest = self.path.join(&self.config.dest()); - - let src = self.path.join(&self.config.src()); + let dest = self.config.dest(); + let src = self.config.src(); // Hacky way to check if the directory exists... Until PathExt moves to stable match metadata(&dest) { @@ -91,12 +88,12 @@ impl MDBook { } pub fn set_dest(mut self, dest: PathBuf) -> Self { - self.config.set_dest(dest); + self.config = self.config.set_dest(dest); self } pub fn set_src(mut self, src: PathBuf) -> Self { - self.config.set_src(src); + self.config = self.config.set_src(src); self } diff --git a/src/mdbook/mod.rs b/src/mdbook/mod.rs new file mode 100644 index 00000000..c6cd178f --- /dev/null +++ b/src/mdbook/mod.rs @@ -0,0 +1,2 @@ +pub mod mdbook; +mod bookconfig;