Clean up command line arguments.
This commit is contained in:
30
src/cli.rs
Normal file
30
src/cli.rs
Normal 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>,
|
||||||
|
}
|
||||||
34
src/main.rs
34
src/main.rs
@@ -1,37 +1,23 @@
|
|||||||
|
use clap::Parser;
|
||||||
mod blog;
|
mod blog;
|
||||||
|
mod cli;
|
||||||
mod error;
|
mod error;
|
||||||
mod og;
|
mod og;
|
||||||
|
|
||||||
use clap::Parser;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use crate::blog::Meta;
|
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() {
|
fn main() {
|
||||||
let config = Args::parse();
|
let config = cli::Args::parse();
|
||||||
|
|
||||||
blog::FALLBACK_META_PATH.get_or_init(|| config.fallback_meta);
|
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");
|
println!("Loaded FallbackMeta");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user