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.

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