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.

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