Complete #1
This commit is contained in:
85
src/cli.rs
85
src/cli.rs
@@ -1,34 +1,81 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::{Args, Parser, Subcommand, ValueEnum};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(author, version, about)]
|
#[clap(author, version, about)]
|
||||||
pub struct Args {
|
pub struct Cli {
|
||||||
/// Path to fallback meta file.
|
#[command(subcommand)]
|
||||||
#[arg(value_hint = clap::ValueHint::DirPath, required = true)]
|
pub command: Commands,
|
||||||
pub fallback_meta: PathBuf,
|
|
||||||
|
|
||||||
#[clap(flatten)]
|
#[arg(value_hint = clap::ValueHint::DirPath, default_value = format!("./target"))]
|
||||||
pub single_or_batch: SingleOrBatch,
|
target_dir: PathBuf,
|
||||||
|
|
||||||
#[arg(short, long, value_hint = clap::ValueHint::DirPath)]
|
|
||||||
pub single_post: Option<PathBuf>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Subcommand)]
|
||||||
#[group(required = true, multiple = false)]
|
pub enum Commands {
|
||||||
pub struct SingleOrBatch {
|
#[command(arg_required_else_help = true)]
|
||||||
/// Path to a single meta to process.
|
Build {
|
||||||
#[arg(short = 'i', long, value_hint = clap::ValueHint::DirPath)]
|
#[clap(flatten)]
|
||||||
pub single_meta: Option<PathBuf>,
|
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(
|
#[arg(
|
||||||
short,
|
short,
|
||||||
long,
|
long,
|
||||||
value_hint = clap::ValueHint::DirPath,
|
value_hint = clap::ValueHint::DirPath,
|
||||||
default_value = format!("../test_tree/")
|
default_value = format!("cutinews.lock")
|
||||||
)]
|
)]
|
||||||
pub blog_path: Option<PathBuf>,
|
lock_file: PathBuf,
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/main.rs
27
src/main.rs
@@ -4,12 +4,32 @@ mod convert;
|
|||||||
mod error;
|
mod error;
|
||||||
mod og;
|
mod og;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::blog::Meta;
|
use crate::blog::Meta;
|
||||||
|
use crate::cli::Commands;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
fn main() {
|
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);
|
load_fb_meta(&config);
|
||||||
|
|
||||||
@@ -30,11 +50,12 @@ fn main() {
|
|||||||
.as_path(),
|
.as_path(),
|
||||||
)
|
)
|
||||||
.expect("Failed to deserialize single_meta file");
|
.expect("Failed to deserialize single_meta file");
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fallback Meta Setup
|
/// Fallback Meta Setup
|
||||||
fn load_fb_meta(config: &cli::Args) {
|
fn load_fb_meta(path: PathBuf) {
|
||||||
blog::FALLBACK_META_PATH.get_or_init(|| config.fallback_meta.to_owned());
|
blog::FALLBACK_META_PATH.get_or_init(|| path);
|
||||||
|
|
||||||
// Trigger OnceLock loading of fallback_meta path.
|
// Trigger OnceLock loading of fallback_meta path.
|
||||||
Meta::default();
|
Meta::default();
|
||||||
|
|||||||
Reference in New Issue
Block a user