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.

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