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.

70 lines
1.9KB

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