Clean up command line arguments.

This commit is contained in:
Olivia Brooks
2025-10-13 14:41:45 -04:00
parent 261e5f525b
commit 0fc2e60cd9
2 changed files with 40 additions and 24 deletions

30
src/cli.rs Normal file
View File

@@ -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<PathBuf>,
/// Path to blog root for batch processing.
#[arg(
short,
long,
value_hint = clap::ValueHint::DirPath,
default_value = format!("../test_tree/")
)]
pub blog_path: Option<PathBuf>,
}

View File

@@ -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");
}