zola/src/main.rs

87 lines
2.2 KiB
Rust
Raw Normal View History

#![feature(proc_macro)]
2016-12-06 05:51:33 +00:00
#[macro_use] extern crate clap;
#[macro_use] extern crate error_chain;
2016-12-06 08:27:03 +00:00
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate serde_derive;
2016-12-06 06:55:17 +00:00
extern crate toml;
2016-12-06 08:27:03 +00:00
extern crate walkdir;
extern crate pulldown_cmark;
extern crate regex;
2016-12-06 11:53:14 +00:00
extern crate tera;
extern crate glob;
2016-12-06 05:51:33 +00:00
2016-12-13 06:22:24 +00:00
mod utils;
2016-12-06 05:51:33 +00:00
mod config;
mod errors;
mod cmd;
2016-12-06 08:27:03 +00:00
mod page;
mod front_matter;
2016-12-06 05:51:33 +00:00
2016-12-06 06:55:17 +00:00
use config::Config;
2016-12-06 08:27:03 +00:00
// Get and parse the config.
// If it doesn't succeed, exit
2016-12-06 06:55:17 +00:00
fn get_config() -> Config {
match Config::from_file("config.toml") {
Ok(c) => c,
Err(e) => {
println!("Error: {}", e);
::std::process::exit(1);
}
}
}
2016-12-06 05:51:33 +00:00
fn main() {
let matches = clap_app!(myapp =>
(version: crate_version!())
(author: "Vincent Prouillet")
(about: "Static site generator")
(@setting SubcommandRequiredElseHelp)
(@subcommand new =>
(about: "Create a new Gutenberg project")
(@arg name: +required "Name of the project. Will create a directory with that name in the current directory")
)
2016-12-06 08:27:03 +00:00
(@subcommand build =>
(about: "Builds the site")
)
2016-12-06 05:51:33 +00:00
).get_matches();
match matches.subcommand() {
("new", Some(matches)) => {
match cmd::create_new_project(matches.value_of("name").unwrap()) {
2016-12-06 08:27:03 +00:00
Ok(()) => {
println!("Project created");
2016-12-13 06:22:24 +00:00
println!("You will now need to set a theme in `config.toml`");
2016-12-06 08:27:03 +00:00
},
Err(e) => {
println!("Error: {}", e);
::std::process::exit(1);
},
};
},
("build", Some(_)) => {
2016-12-06 08:27:03 +00:00
match cmd::build(get_config()) {
Ok(()) => {
2016-12-13 06:22:24 +00:00
println!("Project built.");
2016-12-06 08:27:03 +00:00
},
Err(e) => {
2016-12-13 06:22:24 +00:00
println!("Failed to build the site");
println!("Error: {}", e);
for e in e.iter().skip(1) {
println!("Reason: {}", e)
}
2016-12-06 08:27:03 +00:00
::std::process::exit(1);
},
2016-12-06 05:51:33 +00:00
};
},
_ => unreachable!(),
}
}