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.

82 lines
2.6KB

  1. #[macro_use]
  2. extern crate clap;
  3. #[macro_use]
  4. extern crate error_chain;
  5. extern crate gutenberg;
  6. extern crate chrono;
  7. extern crate term_painter;
  8. extern crate staticfile;
  9. extern crate iron;
  10. extern crate mount;
  11. extern crate notify;
  12. extern crate ws;
  13. use std::time::Instant;
  14. mod cmd;
  15. mod console;
  16. mod rebuild;
  17. fn main() {
  18. let matches = clap_app!(Gutenberg =>
  19. (version: crate_version!())
  20. (author: "Vincent Prouillet")
  21. (about: "Static site generator")
  22. (@setting SubcommandRequiredElseHelp)
  23. (@arg config: -c --config +takes_value "Path to a config file other than config.toml")
  24. (@subcommand init =>
  25. (about: "Create a new Gutenberg project")
  26. (@arg name: +required "Name of the project. Will create a directory with that name in the current directory")
  27. )
  28. (@subcommand build =>
  29. (about: "Builds the site")
  30. )
  31. (@subcommand serve =>
  32. (about: "Serve the site. Rebuild and reload on change automatically")
  33. (@arg interface: "Interface to bind on (default to 127.0.0.1)")
  34. (@arg port: "Which port to use (default to 1111)")
  35. )
  36. ).get_matches();
  37. let config_file = matches.value_of("config").unwrap_or("config.toml");
  38. match matches.subcommand() {
  39. ("init", Some(matches)) => {
  40. match cmd::create_new_project(matches.value_of("name").unwrap()) {
  41. Ok(()) => console::success("Project created"),
  42. Err(e) => {
  43. console::unravel_errors("Failed to create the project", &e);
  44. ::std::process::exit(1);
  45. },
  46. };
  47. },
  48. ("build", Some(_)) => {
  49. console::info("Building site...");
  50. let start = Instant::now();
  51. match cmd::build(config_file) {
  52. Ok(()) => console::report_elapsed_time(start),
  53. Err(e) => {
  54. console::unravel_errors("Failed to build the site", &e);
  55. ::std::process::exit(1);
  56. },
  57. };
  58. },
  59. ("serve", Some(matches)) => {
  60. let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
  61. let port = matches.value_of("port").unwrap_or("1111");
  62. console::info("Building site...");
  63. match cmd::serve(interface, port, config_file) {
  64. Ok(()) => (),
  65. Err(e) => {
  66. console::unravel_errors("Failed to build the site", &e);
  67. ::std::process::exit(1);
  68. },
  69. };
  70. },
  71. _ => unreachable!(),
  72. }
  73. }