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.

74 lines
2.1KB

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