use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use crate::plugins::PluginRegistry;
#[derive(Parser)]
#[command(about = "A static site generator for Markdown content")]
#[command(version = env!("CARGO_PKG_VERSION"))]
struct CliArgs {
#[command(subcommand)]
command: Commands,
#[arg(short = 'i', long = "input", default_value = "content", global = true)]
input: PathBuf,
#[arg(short = 'o', long = "output", default_value = "dist", global = true)]
output: PathBuf,
}
#[derive(Subcommand)]
enum Commands {
Generate,
Dev {
#[arg(short = 'p', long = "port", default_value = "3000")]
port: u16,
},
}
pub struct SherwoodCli {
plugin_registry: Option<PluginRegistry>,
}
impl Default for SherwoodCli {
fn default() -> Self {
Self::new()
}
}
impl SherwoodCli {
pub fn new() -> Self {
Self {
plugin_registry: None,
}
}
pub fn with_plugins(mut self, registry: PluginRegistry) -> Self {
self.plugin_registry = Some(registry);
self
}
pub async fn run(self) -> Result<()> {
let args = CliArgs::parse();
match args.command {
Commands::Generate => {
crate::generate_site_with_plugins(&args.input, &args.output, self.plugin_registry)
.await
}
Commands::Dev { port } => {
crate::run_dev_server_with_plugins(
&args.input,
&args.output,
port,
self.plugin_registry,
)
.await
}
}
}
}