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.

87 lines
2.2KB

  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 utils;
  13. mod config;
  14. mod errors;
  15. mod cmd;
  16. mod page;
  17. mod front_matter;
  18. use config::Config;
  19. // Get and parse the config.
  20. // If it doesn't succeed, exit
  21. fn get_config() -> Config {
  22. match Config::from_file("config.toml") {
  23. Ok(c) => c,
  24. Err(e) => {
  25. println!("Error: {}", e);
  26. ::std::process::exit(1);
  27. }
  28. }
  29. }
  30. fn main() {
  31. let matches = clap_app!(myapp =>
  32. (version: crate_version!())
  33. (author: "Vincent Prouillet")
  34. (about: "Static site generator")
  35. (@setting SubcommandRequiredElseHelp)
  36. (@subcommand new =>
  37. (about: "Create a new Gutenberg project")
  38. (@arg name: +required "Name of the project. Will create a directory with that name in the current directory")
  39. )
  40. (@subcommand build =>
  41. (about: "Builds the site")
  42. )
  43. ).get_matches();
  44. match matches.subcommand() {
  45. ("init", Some(matches)) => {
  46. match cmd::create_new_project(matches.value_of("name").unwrap()) {
  47. Ok(()) => {
  48. println!("Project created");
  49. println!("You will now need to set a theme in `config.toml`");
  50. },
  51. Err(e) => {
  52. println!("Error: {}", e);
  53. ::std::process::exit(1);
  54. },
  55. };
  56. },
  57. ("build", Some(_)) => {
  58. match cmd::build(get_config()) {
  59. Ok(()) => {
  60. println!("Project built.");
  61. },
  62. Err(e) => {
  63. println!("Failed to build the site");
  64. println!("Error: {}", e);
  65. for e in e.iter().skip(1) {
  66. println!("Reason: {}", e)
  67. }
  68. ::std::process::exit(1);
  69. },
  70. };
  71. },
  72. _ => unreachable!(),
  73. }
  74. }