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.

73 lines
2.1KB

  1. extern crate actix;
  2. extern crate actix_web;
  3. #[macro_use]
  4. extern crate clap;
  5. extern crate chrono;
  6. extern crate notify;
  7. extern crate term_painter;
  8. extern crate url;
  9. extern crate ws;
  10. extern crate ctrlc;
  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. extern crate rebuild;
  18. use std::time::Instant;
  19. mod cmd;
  20. mod console;
  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();
  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. let base_url = matches.value_of("base_url").unwrap();
  53. console::info("Building site...");
  54. match cmd::serve(interface, port, output_dir, base_url, config_file) {
  55. Ok(()) => (),
  56. Err(e) => {
  57. console::unravel_errors("", &e);
  58. ::std::process::exit(1);
  59. },
  60. };
  61. },
  62. _ => unreachable!(),
  63. }
  64. }