archive
/
md-pdf-rs
Archived
1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
md-pdf-rs/src/main.rs

65 lines
1.3 KiB
Rust
Raw Normal View History

2017-07-18 14:27:50 +01:00
#[macro_use]
extern crate clap;
#[macro_use]
extern crate serde_derive;
2017-07-17 09:52:22 +01:00
extern crate serde_yaml;
2017-08-14 21:45:23 +01:00
extern crate pandoc;
2017-08-27 21:16:40 +01:00
extern crate wkhtmltopdf;
2017-08-31 20:46:36 +01:00
extern crate sciter;
2017-07-17 09:52:22 +01:00
2017-08-14 21:22:53 +01:00
use std::io::{self, Write};
use std::process::exit;
2017-07-12 14:01:52 +01:00
mod args;
2017-07-17 09:52:22 +01:00
mod config;
2017-07-20 09:14:48 +01:00
mod input;
2017-07-26 15:22:20 +01:00
mod utils;
2017-08-14 21:45:23 +01:00
mod build;
2017-08-27 23:42:56 +01:00
mod output;
2017-09-06 18:20:45 +01:00
mod processors;
mod html;
2017-09-06 21:40:48 +01:00
mod assets;
2017-07-12 14:01:52 +01:00
2017-07-12 14:40:25 +01:00
#[cfg(test)]
mod tests;
2017-08-14 21:22:53 +01:00
use clap::ArgMatches;
2017-09-06 18:20:45 +01:00
use input::read_input_files;
2017-08-14 21:22:53 +01:00
use config::Config;
2017-09-06 18:20:45 +01:00
use build::build_input;
use output::output;
use utils::ok_or_exit;
2017-08-14 21:22:53 +01:00
2017-09-06 18:20:45 +01:00
fn build(config: Config) -> Result<(), String> {
let input = try!(read_input_files(config.input.clone()));
let raw_html = try!(build_input(config.clone(), input));
println!("{}", raw_html);
try!(output(config, raw_html));
return Ok(());
2017-08-14 21:22:53 +01:00
}
2017-08-14 22:10:05 +01:00
fn get_config(args: ArgMatches) -> Config {
2017-08-14 21:22:53 +01:00
let mut config = ok_or_exit(config::get_config());
config.verbosity = args::get_verbose(args);
return config;
}
2017-07-01 21:10:25 +01:00
fn main() {
2017-07-17 10:02:58 +01:00
let args = args::get_matches();
2017-08-14 21:22:53 +01:00
let subcommand = args.subcommand_name().expect("subcommand error");
match subcommand {
"build" => {
2017-08-14 22:10:05 +01:00
let config = get_config(args.clone());
2017-09-06 18:20:45 +01:00
utils::ok_or_exit(build(config));
2017-08-14 21:22:53 +01:00
}
cmd => {
writeln!(io::stderr(), "Unknown command {}.", cmd).unwrap();
exit(1);
}
2017-07-17 10:02:58 +01:00
}
2017-07-01 21:10:25 +01:00
}