This commit is contained in:
Olivia Brooks
2025-10-14 13:03:28 -04:00
parent fa9997a650
commit 3937777255
2 changed files with 90 additions and 22 deletions

View File

@@ -1,34 +1,81 @@
use std::path::PathBuf;
use clap::Parser;
use clap::{Args, Parser, Subcommand, ValueEnum};
#[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,
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
#[clap(flatten)]
pub single_or_batch: SingleOrBatch,
#[arg(short, long, value_hint = clap::ValueHint::DirPath)]
pub single_post: Option<PathBuf>,
#[arg(value_hint = clap::ValueHint::DirPath, default_value = format!("./target"))]
target_dir: PathBuf,
}
#[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>,
#[derive(Debug, Subcommand)]
pub enum Commands {
#[command(arg_required_else_help = true)]
Build {
#[clap(flatten)]
lockfile: LockfileAccess,
/// Path to blog root for batch processing.
/// Path to fallback meta file.
#[arg(value_hint = clap::ValueHint::DirPath, required = true)]
fallback_meta: PathBuf,
/// Path to a single meta to process.
#[arg(short, long, value_hint = clap::ValueHint::DirPath, required = true)]
meta: PathBuf,
/// Path to markdown post.
#[arg(short, long, value_hint = clap::ValueHint::DirPath, required = true)]
post_md: PathBuf,
/// Path to html template.
#[arg(short, long, value_hint = clap::ValueHint::DirPath, required = true)]
template_html: PathBuf,
},
Update {
#[clap(flatten)]
lockfile: LockfileAccess,
},
#[command(arg_required_else_help = true)]
Refresh {
#[clap(flatten)]
lockfile: LockfileAccess,
#[arg(required = true)]
scope: RefreshScope,
},
Clean,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Subcommand, ValueEnum)]
pub enum RefreshScope {
Image,
Post,
All, // Both of the above
}
#[derive(Debug, Args)]
pub struct LockfileAccess {
/// Path to blog root for batch updating.
#[arg(
long,
value_hint = clap::ValueHint::DirPath,
default_value = format!("./")
)]
post_tree: PathBuf,
/// Path to lockfile for batch updating.
#[arg(
short,
long,
value_hint = clap::ValueHint::DirPath,
default_value = format!("../test_tree/")
default_value = format!("cutinews.lock")
)]
pub blog_path: Option<PathBuf>,
lock_file: PathBuf,
}

View File

@@ -4,12 +4,32 @@ mod convert;
mod error;
mod og;
use std::path::PathBuf;
use crate::blog::Meta;
use crate::cli::Commands;
use clap::Parser;
fn main() {
let config = cli::Args::parse();
let config = cli::Cli::parse();
dbg!(&config);
match config.command {
Commands::Build {
lockfile,
fallback_meta,
meta,
post_md,
template_html,
} => (),
Commands::Update { lockfile } => (),
Commands::Refresh { lockfile, scope } => (),
Commands::Clean => (),
}
/*
load_fb_meta(&config);
@@ -30,11 +50,12 @@ fn main() {
.as_path(),
)
.expect("Failed to deserialize single_meta file");
*/
}
/// Fallback Meta Setup
fn load_fb_meta(config: &cli::Args) {
blog::FALLBACK_META_PATH.get_or_init(|| config.fallback_meta.to_owned());
fn load_fb_meta(path: PathBuf) {
blog::FALLBACK_META_PATH.get_or_init(|| path);
// Trigger OnceLock loading of fallback_meta path.
Meta::default();