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.1KB

  1. extern crate actix_web;
  2. #[macro_use]
  3. extern crate clap;
  4. extern crate chrono;
  5. extern crate notify;
  6. extern crate term_painter;
  7. extern crate url;
  8. extern crate ws;
  9. extern crate ctrlc;
  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. extern crate rebuild;
  17. use std::time::Instant;
  18. mod cmd;
  19. mod console;
  20. mod cli;
  21. mod prompt;
  22. fn main() {
  23. let matches = cli::build_cli().get_matches();
  24. let config_file = matches.value_of("config").unwrap();
  25. match matches.subcommand() {
  26. ("init", Some(matches)) => {
  27. match cmd::create_new_project(matches.value_of("name").unwrap()) {
  28. Ok(()) => (),
  29. Err(e) => {
  30. console::unravel_errors("Failed to create the project", &e);
  31. ::std::process::exit(1);
  32. },
  33. };
  34. },
  35. ("build", Some(matches)) => {
  36. console::info("Building site...");
  37. let start = Instant::now();
  38. let output_dir = matches.value_of("output_dir").unwrap();
  39. match cmd::build(config_file, matches.value_of("base_url"), output_dir) {
  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. let output_dir = matches.value_of("output_dir").unwrap();
  51. let base_url = matches.value_of("base_url").unwrap();
  52. console::info("Building site...");
  53. match cmd::serve(interface, port, output_dir, base_url, config_file) {
  54. Ok(()) => (),
  55. Err(e) => {
  56. console::unravel_errors("", &e);
  57. ::std::process::exit(1);
  58. },
  59. };
  60. },
  61. _ => unreachable!(),
  62. }
  63. }