use crate::config::OutputConfig;
use clap::Args;
use std::path::PathBuf;
#[derive(Args, Debug)]
pub struct OutputOptions {
#[arg(long)]
dry_run: bool,
#[arg(short = 'o', long, value_name = "FILE/FOLDER")]
output: Option<PathBuf>,
#[arg(short = 'f', long, requires = "output", requires = "recursive")]
flatten: bool,
#[arg(short = 'p', long, value_name = "PREFIX")]
prefix: Option<String>,
#[arg(short = 's', long, value_name = "SUFFIX")]
suffix: Option<String>,
#[arg(short = 'y', long)]
overwrite: bool,
}
impl From<OutputOptions> for OutputConfig {
fn from(opts: OutputOptions) -> Self {
OutputConfig::new(
opts.dry_run,
opts.flatten,
opts.output,
opts.overwrite,
opts.prefix,
opts.suffix,
)
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
#[test]
fn parse_output_options() {
let opts = OutputOptions {
dry_run: true,
output: Some(PathBuf::from("output")),
flatten: true,
prefix: Some("prefix".to_string()),
suffix: Some("suffix".to_string()),
overwrite: true,
};
let config = OutputConfig::from(opts);
assert!(config.dry_run());
assert!(config.flatten());
assert_eq!(config.output_root(), &Some(PathBuf::from("output")));
assert!(config.overwrite());
assert_eq!(config.prefix(), &Some("prefix".to_string()));
assert_eq!(config.suffix(), &Some("suffix".to_string()));
}
}