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

57 lines
1.1 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-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 process;
mod input;
2017-07-26 15:22:20 +01:00
mod utils;
2017-08-14 21:45:23 +01:00
mod build;
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;
use config::Config;
fn ok_or_exit<T>(res: Result<T, String>) -> T {
return match res {
Ok(k) => k,
Err(err) => {
writeln!(io::stderr(), "Error: {:?}", err).unwrap();
exit(1);
}
};
}
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-08-14 21:22:53 +01:00
ok_or_exit(process::build(config));
}
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
}