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.

68 lines
1.8KB

  1. #[macro_use]
  2. extern crate clap;
  3. extern crate chrono;
  4. extern crate term_painter;
  5. extern crate staticfile;
  6. extern crate iron;
  7. extern crate mount;
  8. extern crate notify;
  9. extern crate ws;
  10. extern crate site;
  11. #[macro_use]
  12. extern crate errors;
  13. extern crate content;
  14. extern crate front_matter;
  15. extern crate utils;
  16. use std::time::Instant;
  17. mod cmd;
  18. mod console;
  19. mod rebuild;
  20. mod cli;
  21. fn main() {
  22. let matches = cli::build_cli().get_matches();
  23. let config_file = matches.value_of("config").unwrap_or("config.toml");
  24. match matches.subcommand() {
  25. ("init", Some(matches)) => {
  26. match cmd::create_new_project(matches.value_of("name").unwrap()) {
  27. Ok(()) => console::success("Project created"),
  28. Err(e) => {
  29. console::unravel_errors("Failed to create the project", &e);
  30. ::std::process::exit(1);
  31. },
  32. };
  33. },
  34. ("build", Some(_)) => {
  35. console::info("Building site...");
  36. let start = Instant::now();
  37. match cmd::build(config_file) {
  38. Ok(()) => console::report_elapsed_time(start),
  39. Err(e) => {
  40. console::unravel_errors("Failed to build the site", &e);
  41. ::std::process::exit(1);
  42. },
  43. };
  44. },
  45. ("serve", Some(matches)) => {
  46. let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
  47. let port = matches.value_of("port").unwrap_or("1111");
  48. console::info("Building site...");
  49. match cmd::serve(interface, port, config_file) {
  50. Ok(()) => (),
  51. Err(e) => {
  52. console::unravel_errors("", &e);
  53. ::std::process::exit(1);
  54. },
  55. };
  56. },
  57. _ => unreachable!(),
  58. }
  59. }