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.

76 lines
1.9KB

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