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.

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