A static site generator written in Rust
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.

main.rs 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. extern crate clap;
  2. use clap::{App, Arg};
  3. use std::env;
  4. fn main() {
  5. let matches = App::new("casaubon")
  6. .version("0.3.2")
  7. .author("Dylan Baker")
  8. .about("Highly opinionated static site generator")
  9. .arg(
  10. Arg::with_name("command")
  11. .required(true)
  12. .possible_values(&["build", "new", "watch"])
  13. .index(1),
  14. )
  15. .arg(Arg::with_name("drafts").short("d").long("drafts"))
  16. .arg(
  17. Arg::with_name("name")
  18. .required_if("command", "new")
  19. .index(2),
  20. )
  21. .get_matches();
  22. let include_drafts = match matches.occurrences_of("drafts") {
  23. 0 => false,
  24. 1 => true,
  25. _ => true,
  26. };
  27. let command = matches.value_of("command").unwrap();
  28. if command == "build" {
  29. casaubon::build(
  30. include_drafts,
  31. &env::current_dir().expect("Can't read current directory"),
  32. );
  33. } else if command == "new" {
  34. casaubon::new(
  35. &matches.value_of("name").unwrap(),
  36. &env::current_dir().expect("Can't read current directory"),
  37. );
  38. } else if command == "watch" {
  39. casaubon::build(
  40. include_drafts,
  41. &env::current_dir().expect("Can't read current directory"),
  42. );
  43. casaubon::watch(
  44. include_drafts,
  45. &env::current_dir().expect("Can't read current directory"),
  46. )
  47. .expect("Error while watching posts directory");
  48. }
  49. }