From 0fc2e60cd94620ef06d00bbd3783e911d7054849 Mon Sep 17 00:00:00 2001 From: Olivia Brooks <109807080+Cutieguwu@users.noreply.github.com> Date: Mon, 13 Oct 2025 14:41:45 -0400 Subject: [PATCH] Clean up command line arguments. --- src/cli.rs | 30 ++++++++++++++++++++++++++++++ src/main.rs | 34 ++++++++++------------------------ 2 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 src/cli.rs diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..7a20235 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,30 @@ +use clap::Parser; +use std::path::PathBuf; + +#[derive(Debug, Parser)] +#[clap(author, version, about)] +pub struct Args { + /// Path to fallback meta file. + #[arg(value_hint = clap::ValueHint::DirPath, required = true)] + pub fallback_meta: PathBuf, + + #[clap(flatten)] + pub single_or_batch: SingleOrBatch, +} + +#[derive(Debug, Parser)] +#[group(required = true, multiple = false)] +pub struct SingleOrBatch { + /// Path to a single meta to process. + #[arg(short = 'i', long, value_hint = clap::ValueHint::DirPath)] + pub single_meta: Option, + + /// Path to blog root for batch processing. + #[arg( + short, + long, + value_hint = clap::ValueHint::DirPath, + default_value = format!("../test_tree/") + )] + pub blog_path: Option, +} diff --git a/src/main.rs b/src/main.rs index cbb751b..2ec3e47 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,37 +1,23 @@ +use clap::Parser; mod blog; +mod cli; mod error; mod og; -use clap::Parser; -use std::path::PathBuf; - use crate::blog::Meta; -#[derive(Debug, Parser)] -#[clap(author, version, about)] -struct Args { - /// Path to blog root. - #[arg( - short = 'i', - long, - value_hint = clap::ValueHint::DirPath, - default_value = format!("../test_tree/") - )] - blog_path: PathBuf, - - #[arg(short, long, value_hint = clap::ValueHint::DirPath)] - fallback_meta: PathBuf, - - #[arg(short, long, value_hint = clap::ValueHint::DirPath)] - single_meta: PathBuf, -} - fn main() { - let config = Args::parse(); + let config = cli::Args::parse(); blog::FALLBACK_META_PATH.get_or_init(|| config.fallback_meta); - let _meta = Meta::try_from(config.single_meta).expect("Failed to deserialize single_meta file"); + let _meta = Meta::try_from( + config + .single_or_batch + .single_meta + .expect("No patch for single file processing."), + ) + .expect("Failed to deserialize single_meta file"); println!("Loaded FallbackMeta"); }