|
|
@ -16,17 +16,17 @@ use std::sync::mpsc::channel;
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
use structopt::StructOpt;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
#[derive(StructOpt, Debug, Clone)]
|
|
|
|
struct Opt {
|
|
|
|
struct Opt {
|
|
|
|
#[structopt(subcommand)]
|
|
|
|
#[structopt(subcommand)]
|
|
|
|
sub_command: SubCommand,
|
|
|
|
sub_command: SubCommand,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
#[derive(StructOpt, Debug, Clone)]
|
|
|
|
#[structopt()]
|
|
|
|
#[structopt()]
|
|
|
|
enum SubCommand {
|
|
|
|
enum SubCommand {
|
|
|
|
/// Watch the document and its imports and render on change.
|
|
|
|
/// Watch the document and its imports and render on change.
|
|
|
|
Watch(RenderOptions),
|
|
|
|
Watch(WatchOptions),
|
|
|
|
|
|
|
|
|
|
|
|
/// Parse and render the document.
|
|
|
|
/// Parse and render the document.
|
|
|
|
Render(RenderOptions),
|
|
|
|
Render(RenderOptions),
|
|
|
@ -35,7 +35,7 @@ enum SubCommand {
|
|
|
|
ClearCache,
|
|
|
|
ClearCache,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
#[derive(StructOpt, Debug, Clone)]
|
|
|
|
#[structopt()]
|
|
|
|
#[structopt()]
|
|
|
|
struct RenderOptions {
|
|
|
|
struct RenderOptions {
|
|
|
|
/// Path to the input file
|
|
|
|
/// Path to the input file
|
|
|
@ -49,10 +49,17 @@ struct RenderOptions {
|
|
|
|
/// the output format
|
|
|
|
/// the output format
|
|
|
|
#[structopt(short, long, default_value = "html")]
|
|
|
|
#[structopt(short, long, default_value = "html")]
|
|
|
|
format: String,
|
|
|
|
format: String,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(StructOpt, Debug, Clone)]
|
|
|
|
|
|
|
|
#[structopt()]
|
|
|
|
|
|
|
|
struct WatchOptions {
|
|
|
|
|
|
|
|
/// The amount of time in milliseconds to wait after changes before rendering
|
|
|
|
|
|
|
|
#[structopt(long, default_value = "500")]
|
|
|
|
|
|
|
|
debounce: u64,
|
|
|
|
|
|
|
|
|
|
|
|
/// Don't use the cache
|
|
|
|
#[structopt(flatten)]
|
|
|
|
#[structopt(long)]
|
|
|
|
render_options: RenderOptions,
|
|
|
|
no_cache: bool,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
fn main() {
|
|
|
@ -101,16 +108,17 @@ fn get_level_style(level: Level) -> colored::Color {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Watches a file with all of its imports and renders on change
|
|
|
|
/// Watches a file with all of its imports and renders on change
|
|
|
|
fn watch(opt: &RenderOptions) {
|
|
|
|
fn watch(opt: &WatchOptions) {
|
|
|
|
let parser = render(opt);
|
|
|
|
let parser = render(&opt.render_options);
|
|
|
|
let (tx, rx) = channel();
|
|
|
|
let (tx, rx) = channel();
|
|
|
|
let mut watcher = watcher(tx, Duration::from_millis(250)).unwrap();
|
|
|
|
let mut watcher = watcher(tx, Duration::from_millis(opt.debounce)).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
for path in parser.get_paths() {
|
|
|
|
for path in parser.get_paths() {
|
|
|
|
watcher.watch(path, RecursiveMode::NonRecursive).unwrap();
|
|
|
|
watcher.watch(path, RecursiveMode::NonRecursive).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while let Ok(_) = rx.recv() {
|
|
|
|
while let Ok(_) = rx.recv() {
|
|
|
|
println!("---");
|
|
|
|
println!("---");
|
|
|
|
let parser = render(opt);
|
|
|
|
let parser = render(&opt.render_options);
|
|
|
|
for path in parser.get_paths() {
|
|
|
|
for path in parser.get_paths() {
|
|
|
|
watcher.watch(path, RecursiveMode::NonRecursive).unwrap();
|
|
|
|
watcher.watch(path, RecursiveMode::NonRecursive).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -129,11 +137,7 @@ fn render(opt: &RenderOptions) -> Parser {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let start = Instant::now();
|
|
|
|
let start = Instant::now();
|
|
|
|
|
|
|
|
|
|
|
|
let mut parser = Parser::with_defaults(
|
|
|
|
let mut parser = Parser::with_defaults(ParserOptions::default().add_path(opt.input.clone()));
|
|
|
|
ParserOptions::default()
|
|
|
|
|
|
|
|
.add_path(opt.input.clone())
|
|
|
|
|
|
|
|
.use_cache(!opt.no_cache),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
let document = parser.parse();
|
|
|
|
let document = parser.parse();
|
|
|
|
|
|
|
|
|
|
|
|
log::info!("Parsing + Processing took: {:?}", start.elapsed());
|
|
|
|
log::info!("Parsing + Processing took: {:?}", start.elapsed());
|
|
|
|