You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.0KB

  1. #![feature(proc_macro)]
  2. #[macro_use] extern crate clap;
  3. #[macro_use] extern crate error_chain;
  4. #[macro_use] extern crate lazy_static;
  5. #[macro_use] extern crate serde_derive;
  6. extern crate toml;
  7. extern crate walkdir;
  8. extern crate pulldown_cmark;
  9. extern crate regex;
  10. extern crate tera;
  11. extern crate glob;
  12. mod config;
  13. mod errors;
  14. mod cmd;
  15. mod page;
  16. mod front_matter;
  17. use config::Config;
  18. // Get and parse the config.
  19. // If it doesn't succeed, exit
  20. fn get_config() -> Config {
  21. match Config::from_file("config.toml") {
  22. Ok(c) => c,
  23. Err(e) => {
  24. println!("Error: {}", e);
  25. ::std::process::exit(1);
  26. }
  27. }
  28. }
  29. fn main() {
  30. let matches = clap_app!(myapp =>
  31. (version: crate_version!())
  32. (author: "Vincent Prouillet")
  33. (about: "Static site generator")
  34. (@setting SubcommandRequiredElseHelp)
  35. (@subcommand new =>
  36. (about: "Create a new Gutenberg project")
  37. (@arg name: +required "Name of the project. Will create a directory with that name in the current directory")
  38. )
  39. (@subcommand build =>
  40. (about: "Builds the site")
  41. )
  42. ).get_matches();
  43. match matches.subcommand() {
  44. ("new", Some(matches)) => {
  45. match cmd::create_new_project(matches.value_of("name").unwrap()) {
  46. Ok(()) => {
  47. println!("Project created");
  48. },
  49. Err(e) => {
  50. println!("Error: {}", e);
  51. ::std::process::exit(1);
  52. },
  53. };
  54. },
  55. ("build", Some(_)) => {
  56. match cmd::build(get_config()) {
  57. Ok(()) => {
  58. println!("Project built");
  59. },
  60. Err(e) => {
  61. println!("Error: {}", e.iter().nth(1).unwrap().description());
  62. ::std::process::exit(1);
  63. },
  64. };
  65. },
  66. _ => unreachable!(),
  67. }
  68. }