3 use std::path::PathBuf;
5 #[derive(Parser, Debug)]
6 #[command(author = "huck boles")]
7 #[command(version = "0.1.3")]
8 #[command(about = "customizable template driven static site generator")]
9 #[command(long_about = None)]
11 /// root directory [current_dir]
12 #[arg(short, long, value_name = "ROOT_DIR")]
13 pub root: Option<String>,
14 /// source file directory [current_dir/source]
15 #[arg(short, long, value_name = "SOURCE_DIR")]
16 pub source: Option<String>,
17 /// build directory [current_dir/build]
18 #[arg(short, long, value_name = "BUILD_DIR")]
19 pub build: Option<String>,
20 /// pattern directory [current_dir/pattern]
21 #[arg(short, long, value_name = "PATTERN_DIR")]
22 pub pattern: Option<String>,
23 /// builds a single file and outputs on stdout
24 #[arg(short, long, value_name = "FILENAME")]
25 pub file: Option<String>,
26 /// output filetype [html]
27 #[arg(short, long, value_name = "OUTPUT_FILETYPE")]
28 pub output: Option<String>,
29 /// input filetype [markdown]
30 #[arg(short, long, value_name = "INPUT_FILETYPE")]
31 pub input: Option<String>,
32 /// enable extra output. repeated flags give more info
33 #[arg(short, long, action = clap::ArgAction::Count)]
35 /// minimal output [false]
36 #[arg(short, long, default_value_t = false)]
38 /// enable parallel processing [false]
39 #[arg(short = 'l', long, default_value_t = false)]
41 /// create a new skeleton directory [false]
42 #[arg(long, default_value_t = false)]
44 /// clean build directory before building site [false]
45 #[arg(long, default_value_t = false)]
47 /// don't stop on file failure [false]
48 #[arg(long, default_value_t = false)]
50 /// stop on undefined variables and arrays [false]
51 #[arg(long, default_value_t = false)]
53 /// don't call pandoc on source files
54 #[arg(long, default_value_t = false)]
56 /// don't minify resulting html
57 #[arg(long, default_value_t = false)]
61 #[derive(Debug, Clone, Default)]
67 pub file: Option<PathBuf>,
82 pub fn new() -> Self {
85 source: PathBuf::new(),
86 build: PathBuf::new(),
87 pattern: PathBuf::new(),
89 input: String::default(),
90 output: String::default(),
104 impl TryFrom<crate::Opts> for Options {
105 type Error = eyre::Error;
106 fn try_from(value: crate::Opts) -> Result<Self, Self::Error> {
107 let mut opts = Options::new();
109 opts.verbose = value.verbose;
110 opts.quiet = value.quiet;
111 opts.force = value.force;
112 opts.undefined = value.undefined;
113 opts.clean = value.clean;
114 opts.no_pandoc = value.no_pandoc;
115 opts.new = value.new;
116 opts.parallel = value.parallel;
117 opts.minify = !value.no_minify;
119 opts.root = if let Some(root) = value.root.as_deref() {
120 PathBuf::from(root).canonicalize()
122 std::env::current_dir()
125 opts.source = if let Some(source) = value.source.as_deref() {
126 PathBuf::from(source).canonicalize()
128 Ok(opts.root.join("source"))
131 opts.build = if let Some(build) = value.build.as_deref() {
132 PathBuf::from(build).canonicalize()
134 Ok(opts.root.join("build"))
137 opts.pattern = if let Some(pattern) = value.pattern.as_deref() {
138 PathBuf::from(pattern).canonicalize()
140 Ok(opts.root.join("pattern"))
143 if let Some(file) = value.file.as_deref() {
144 opts.file = Some(PathBuf::from(file).canonicalize()?);
147 opts.input = if let Some(input) = value.input {
153 opts.output = if let Some(output) = value.output {
156 String::from("markdown")