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.

85 lines
2.6KB

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