Upgraded binaries to new configuration API
This commit is contained in:
parent
b74c2c18ef
commit
ddb0834da8
|
@ -1,4 +1,5 @@
|
|||
use clap::{App, ArgMatches, SubCommand};
|
||||
use std::path::PathBuf;
|
||||
use clap::{ArgMatches, SubCommand, App};
|
||||
use mdbook::MDBook;
|
||||
use mdbook::errors::Result;
|
||||
use {get_book_dir, open};
|
||||
|
@ -15,10 +16,6 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|||
.arg_from_usage(
|
||||
"--no-create 'Will not create non-existent files linked from SUMMARY.md'",
|
||||
)
|
||||
.arg_from_usage(
|
||||
"--curly-quotes 'Convert straight quotes to curly quotes, except for those \
|
||||
that occur in code blocks and code spans'",
|
||||
)
|
||||
.arg_from_usage(
|
||||
"[dir] 'A directory for your book{n}(Defaults to Current Directory \
|
||||
when omitted)'",
|
||||
|
@ -28,21 +25,16 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|||
// Build command implementation
|
||||
pub fn execute(args: &ArgMatches) -> Result<()> {
|
||||
let book_dir = get_book_dir(args);
|
||||
let book = MDBook::new(&book_dir).read_config()?;
|
||||
let mut book = MDBook::new(&book_dir).read_config()?;
|
||||
|
||||
let mut book = match args.value_of("dest-dir") {
|
||||
Some(dest_dir) => book.with_destination(dest_dir),
|
||||
None => book,
|
||||
};
|
||||
if let Some(dest_dir) = args.value_of("dest-dir") {
|
||||
book.config.book.build_dir = PathBuf::from(dest_dir);
|
||||
}
|
||||
|
||||
if args.is_present("no-create") {
|
||||
book.create_missing = false;
|
||||
}
|
||||
|
||||
if args.is_present("curly-quotes") {
|
||||
book = book.with_curly_quotes(true);
|
||||
}
|
||||
|
||||
book.build()?;
|
||||
|
||||
if args.is_present("open") {
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
|
|||
}
|
||||
|
||||
// Because of `src/book/mdbook.rs#L37-L39`, `dest` will always start with `root`
|
||||
let is_dest_inside_root = book.get_destination().starts_with(book.get_root());
|
||||
let is_dest_inside_root = book.get_destination().starts_with(&book.root);
|
||||
|
||||
if !args.is_present("force") && is_dest_inside_root {
|
||||
println!("\nDo you want a .gitignore to be created? (y/n)");
|
||||
|
|
|
@ -3,7 +3,7 @@ extern crate staticfile;
|
|||
extern crate ws;
|
||||
|
||||
use std;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
use self::iron::{status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response,
|
||||
Set};
|
||||
use clap::{App, ArgMatches, SubCommand};
|
||||
|
@ -29,10 +29,6 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|||
"-d, --dest-dir=[dest-dir] 'The output directory for \
|
||||
your book{n}(Defaults to ./book when omitted)'",
|
||||
)
|
||||
.arg_from_usage(
|
||||
"--curly-quotes 'Convert straight quotes to curly quotes, except \
|
||||
for those that occur in code blocks and code spans'",
|
||||
)
|
||||
.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 \
|
||||
|
@ -53,15 +49,10 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
|
|||
const RELOAD_COMMAND: &'static str = "reload";
|
||||
|
||||
let book_dir = get_book_dir(args);
|
||||
let book = MDBook::new(&book_dir).read_config()?;
|
||||
let mut book = MDBook::new(&book_dir).read_config()?;
|
||||
|
||||
let mut book = match args.value_of("dest-dir") {
|
||||
Some(dest_dir) => book.with_destination(Path::new(dest_dir)),
|
||||
None => book,
|
||||
};
|
||||
|
||||
if args.is_present("curly-quotes") {
|
||||
book = book.with_curly_quotes(true);
|
||||
if let Some(dest_dir) = args.value_of("dest-dir") {
|
||||
book.config.book.build_dir = PathBuf::from(dest_dir);
|
||||
}
|
||||
|
||||
let port = args.value_of("port").unwrap_or("3000");
|
||||
|
@ -73,8 +64,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
|
|||
let address = format!("{}:{}", interface, port);
|
||||
let ws_address = format!("{}:{}", interface, ws_port);
|
||||
|
||||
book.set_livereload(format!(
|
||||
r#"
|
||||
book.livereload = Some(format!(r#"
|
||||
<script type="text/javascript">
|
||||
var socket = new WebSocket("ws://{}:{}");
|
||||
socket.onmessage = function (event) {{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
extern crate notify;
|
||||
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
use self::notify::Watcher;
|
||||
use std::time::Duration;
|
||||
use std::sync::mpsc::channel;
|
||||
|
@ -18,10 +18,6 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|||
"-d, --dest-dir=[dest-dir] 'The output directory for \
|
||||
your book{n}(Defaults to ./book when omitted)'",
|
||||
)
|
||||
.arg_from_usage(
|
||||
"--curly-quotes 'Convert straight quotes to curly quotes, except \
|
||||
for those that occur in code blocks and code spans'",
|
||||
)
|
||||
.arg_from_usage(
|
||||
"[dir] 'A directory for your book{n}(Defaults to \
|
||||
Current Directory when omitted)'",
|
||||
|
@ -31,15 +27,10 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|||
// Watch command implementation
|
||||
pub fn execute(args: &ArgMatches) -> Result<()> {
|
||||
let book_dir = get_book_dir(args);
|
||||
let book = MDBook::new(&book_dir).read_config()?;
|
||||
let mut book = MDBook::new(&book_dir).read_config()?;
|
||||
|
||||
let mut book = match args.value_of("dest-dir") {
|
||||
Some(dest_dir) => book.with_destination(dest_dir),
|
||||
None => book,
|
||||
};
|
||||
|
||||
if args.is_present("curly-quotes") {
|
||||
book = book.with_curly_quotes(true);
|
||||
if let Some(dest_dir) = args.value_of("dest-dir") {
|
||||
book.config.book.build_dir = PathBuf::from(dest_dir);
|
||||
}
|
||||
|
||||
if args.is_present("open") {
|
||||
|
@ -87,7 +78,6 @@ where
|
|||
watcher.watch(book.get_theme_path(), Recursive)
|
||||
.unwrap_or_default();
|
||||
|
||||
|
||||
// Add the book.{json,toml} file to the watcher if it exists, because it's not
|
||||
// located in the source directory
|
||||
if watcher.watch(book.get_root().join("book.json"), NonRecursive)
|
||||
|
|
Loading…
Reference in New Issue