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.

134 lines
5.9KB

  1. use clap::{crate_authors, crate_description, crate_version, App, AppSettings, Arg, SubCommand};
  2. pub fn build_cli() -> App<'static, 'static> {
  3. App::new("zola")
  4. .version(crate_version!())
  5. .author(crate_authors!())
  6. .about(crate_description!())
  7. .setting(AppSettings::SubcommandRequiredElseHelp)
  8. .arg(
  9. Arg::with_name("root")
  10. .short("r")
  11. .long("root")
  12. .takes_value(true)
  13. .default_value(".")
  14. .help("Directory to use as root of project")
  15. )
  16. .arg(
  17. Arg::with_name("config")
  18. .short("c")
  19. .long("config")
  20. .default_value("config.toml")
  21. .takes_value(true)
  22. .help("Path to a config file other than config.toml")
  23. )
  24. .subcommands(vec![
  25. SubCommand::with_name("init")
  26. .about("Create a new Zola project")
  27. .arg(
  28. Arg::with_name("name")
  29. .default_value(".")
  30. .help("Name of the project. Will create a new directory with that name in the current directory")
  31. ),
  32. SubCommand::with_name("build")
  33. .about("Deletes the output directory if there is one and builds the site")
  34. .args(&[
  35. Arg::with_name("base_url")
  36. .short("u")
  37. .long("base-url")
  38. .takes_value(true)
  39. .help("Force the base URL to be that value (default to the one in config.toml)"),
  40. Arg::with_name("output_dir")
  41. .short("o")
  42. .long("output-dir")
  43. .default_value("public")
  44. .takes_value(true)
  45. .help("Outputs the generated site in the given path"),
  46. Arg::with_name("drafts")
  47. .long("drafts")
  48. .takes_value(false)
  49. .help("Include drafts when loading the site"),
  50. ]),
  51. SubCommand::with_name("serve")
  52. .about("Serve the site. Rebuild and reload on change automatically")
  53. .args(&[
  54. Arg::with_name("interface")
  55. .short("i")
  56. .long("interface")
  57. .default_value("127.0.0.1")
  58. .help("Interface to bind on"),
  59. Arg::with_name("port")
  60. .short("p")
  61. .long("port")
  62. .default_value("1111")
  63. .help("Which port to use"),
  64. Arg::with_name("output_dir")
  65. .short("o")
  66. .long("output-dir")
  67. .default_value("public")
  68. .takes_value(true)
  69. .help("Outputs the generated site in the given path"),
  70. Arg::with_name("base_url")
  71. .short("u")
  72. .long("base-url")
  73. .default_value("127.0.0.1")
  74. .takes_value(true)
  75. .help("Changes the base_url"),
  76. Arg::with_name("watch_only")
  77. .long("watch-only")
  78. .takes_value(false)
  79. .help("Do not start a server, just re-build project on changes"),
  80. Arg::with_name("drafts")
  81. .long("drafts")
  82. .takes_value(false)
  83. .help("Include drafts when loading the site"),
  84. Arg::with_name("open")
  85. .short("O")
  86. .long("open")
  87. .takes_value(false)
  88. .help("Open site in the default browser"),
  89. ]),
  90. SubCommand::with_name("check")
  91. .about("Try building the project without rendering it. Checks links")
  92. .args(&[
  93. Arg::with_name("drafts")
  94. .long("drafts")
  95. .takes_value(false)
  96. .help("Include drafts when loading the site"),
  97. ]),
  98. SubCommand::with_name("index")
  99. .about("Create a search index as a stand-alone task, and with additional options")
  100. .args({
  101. let drafts = Arg::with_name("drafts") .long("drafts")
  102. .takes_value(false)
  103. .help("Include drafts when loading the site");
  104. #[cfg(feature = "tantivy-indexing")]
  105. {
  106. let index_type = Arg::with_name("index_type")
  107. .long("index-type")
  108. .short("t")
  109. .takes_value(true)
  110. .possible_values(&["elasticlunr", "tantivy"])
  111. .required(true)
  112. .help("what kind of search index to build");
  113. let output_dir = Arg::with_name("output_dir")
  114. .short("o")
  115. .long("output-dir")
  116. .default_value("public")
  117. .takes_value(true)
  118. .help("Outputs the generated search index files into the provided dir. \
  119. Note: Tantivy indexing produces a directory instead of a file, \
  120. which will be located at output-dir/tantivy-index");
  121. &[drafts, index_type, output_dir]
  122. }
  123. #[cfg(not(feature = "tantivy-indexing"))]
  124. {
  125. &[drafts]
  126. }
  127. }),
  128. ])
  129. }