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.

83 lines
2.5KB

  1. #[macro_use]
  2. extern crate clap;
  3. #[macro_use]
  4. extern crate error_chain;
  5. extern crate gutenberg;
  6. extern crate staticfile;
  7. extern crate iron;
  8. extern crate mount;
  9. extern crate notify;
  10. extern crate ws;
  11. use std::time::Instant;
  12. mod cmd;
  13. fn main() {
  14. let matches = clap_app!(Gutenberg =>
  15. (version: crate_version!())
  16. (author: "Vincent Prouillet")
  17. (about: "Static site generator")
  18. (@setting SubcommandRequiredElseHelp)
  19. (@subcommand init =>
  20. (about: "Create a new Gutenberg project")
  21. (@arg name: +required "Name of the project. Will create a directory with that name in the current directory")
  22. )
  23. (@subcommand build =>
  24. (about: "Builds the site")
  25. )
  26. (@subcommand serve =>
  27. (about: "Serve the site. Rebuild and reload on change automatically")
  28. (@arg interface: "Interface to bind on (default to 127.0.0.1)")
  29. (@arg port: "Which port to use (default to 1111)")
  30. )
  31. ).get_matches();
  32. match matches.subcommand() {
  33. ("init", Some(matches)) => {
  34. match cmd::create_new_project(matches.value_of("name").unwrap()) {
  35. Ok(()) => {
  36. println!("Project created");
  37. },
  38. Err(e) => {
  39. println!("Error: {}", e);
  40. ::std::process::exit(1);
  41. },
  42. };
  43. },
  44. ("build", Some(_)) => {
  45. let start = Instant::now();
  46. match cmd::build() {
  47. Ok(()) => {
  48. let duration = start.elapsed();
  49. println!("Site built in {}s.", duration.as_secs());
  50. },
  51. Err(e) => {
  52. println!("Failed to build the site");
  53. println!("Error: {}", e);
  54. for e in e.iter().skip(1) {
  55. println!("Reason: {}", e)
  56. }
  57. ::std::process::exit(1);
  58. },
  59. };
  60. },
  61. ("serve", Some(matches)) => {
  62. let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
  63. let port = matches.value_of("port").unwrap_or("1111");
  64. match cmd::serve(interface, port) {
  65. Ok(()) => (),
  66. Err(e) => {
  67. println!("Error: {}", e);
  68. ::std::process::exit(1);
  69. },
  70. };
  71. },
  72. _ => unreachable!(),
  73. }
  74. }