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.

94 lines
2.4KB

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