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.

72 lines
2.0KB

  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. let output_dir = matches.value_of("output_dir").unwrap();
  40. match cmd::build(config_file, matches.value_of("base_url"), output_dir) {
  41. Ok(()) => console::report_elapsed_time(start),
  42. Err(e) => {
  43. console::unravel_errors("Failed to build the site", &e);
  44. ::std::process::exit(1);
  45. },
  46. };
  47. },
  48. ("serve", Some(matches)) => {
  49. let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
  50. let port = matches.value_of("port").unwrap_or("1111");
  51. let output_dir = matches.value_of("output_dir").unwrap();
  52. console::info("Building site...");
  53. match cmd::serve(interface, port, output_dir, config_file) {
  54. Ok(()) => (),
  55. Err(e) => {
  56. console::unravel_errors("", &e);
  57. ::std::process::exit(1);
  58. },
  59. };
  60. },
  61. _ => unreachable!(),
  62. }
  63. }