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.

103 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. mod markdown;
  33. fn main() {
  34. let matches = clap_app!(Gutenberg =>
  35. (version: crate_version!())
  36. (author: "Vincent Prouillet")
  37. (about: "Static site generator")
  38. (@setting SubcommandRequiredElseHelp)
  39. (@subcommand init =>
  40. (about: "Create a new Gutenberg project")
  41. (@arg name: +required "Name of the project. Will create a directory with that name in the current directory")
  42. )
  43. (@subcommand build =>
  44. (about: "Builds the site")
  45. )
  46. (@subcommand serve =>
  47. (about: "Serve the site. Rebuild and reload on change automatically")
  48. (@arg interface: "Interface to bind on (default to 127.0.0.1)")
  49. (@arg port: "Which port to use (default to 1111)")
  50. )
  51. ).get_matches();
  52. match matches.subcommand() {
  53. ("init", Some(matches)) => {
  54. match cmd::create_new_project(matches.value_of("name").unwrap()) {
  55. Ok(()) => {
  56. println!("Project created");
  57. },
  58. Err(e) => {
  59. println!("Error: {}", e);
  60. ::std::process::exit(1);
  61. },
  62. };
  63. },
  64. ("build", Some(_)) => {
  65. let start = Instant::now();
  66. match cmd::build() {
  67. Ok(()) => {
  68. let duration = start.elapsed();
  69. println!("Site built in {}s.", duration.as_secs());
  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. ("serve", Some(matches)) => {
  82. let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
  83. let port = matches.value_of("port").unwrap_or("1111");
  84. match cmd::serve(interface, port) {
  85. Ok(()) => (),
  86. Err(e) => {
  87. println!("Error: {}", e);
  88. ::std::process::exit(1);
  89. },
  90. };
  91. },
  92. _ => unreachable!(),
  93. }
  94. }