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.

98 lines
2.8KB

  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. extern crate slug;
  18. use std::time::Instant;
  19. mod utils;
  20. mod config;
  21. mod errors;
  22. mod cmd;
  23. mod page;
  24. mod front_matter;
  25. mod site;
  26. fn main() {
  27. let matches = clap_app!(Gutenberg =>
  28. (version: crate_version!())
  29. (author: "Vincent Prouillet")
  30. (about: "Static site generator")
  31. (@setting SubcommandRequiredElseHelp)
  32. (@subcommand init =>
  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. (@subcommand serve =>
  40. (about: "Serve the site. Rebuild and reload on change automatically")
  41. (@arg interface: "Interface to bind on (default to 127.0.0.1)")
  42. (@arg port: "Which port to use (default to 1111)")
  43. )
  44. ).get_matches();
  45. match matches.subcommand() {
  46. ("init", Some(matches)) => {
  47. match cmd::create_new_project(matches.value_of("name").unwrap()) {
  48. Ok(()) => {
  49. println!("Project created");
  50. },
  51. Err(e) => {
  52. println!("Error: {}", e);
  53. ::std::process::exit(1);
  54. },
  55. };
  56. },
  57. ("build", Some(_)) => {
  58. let start = Instant::now();
  59. match cmd::build() {
  60. Ok(()) => {
  61. let duration = start.elapsed();
  62. println!("Site built in {}s.", duration.as_secs());
  63. },
  64. Err(e) => {
  65. println!("Failed to build the site");
  66. println!("Error: {}", e);
  67. for e in e.iter().skip(1) {
  68. println!("Reason: {}", e)
  69. }
  70. ::std::process::exit(1);
  71. },
  72. };
  73. },
  74. ("serve", Some(matches)) => {
  75. let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
  76. let port = matches.value_of("port").unwrap_or("1111");
  77. match cmd::serve(interface, port) {
  78. Ok(()) => {
  79. println!("Project created");
  80. println!("You will now need to set a theme in `config.toml`");
  81. },
  82. Err(e) => {
  83. println!("Error: {}", e);
  84. ::std::process::exit(1);
  85. },
  86. };
  87. },
  88. _ => unreachable!(),
  89. }
  90. }