From 3b6747e6a12e4ad86cebe0c01941a287c77fa2f7 Mon Sep 17 00:00:00 2001 From: Emil Sayahi <97276123+emmyoh@users.noreply.github.com> Date: Tue, 21 May 2024 21:45:02 -0400 Subject: [PATCH] feat: `build` CLI command TODO: - Serving (with and without watching; default to watching) --- Cargo.toml | 2 +- src/main.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cc86e90..9af8dbb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ required-features = ["cli"] [dependencies] chrono = { version = "0.4.38", features = ["serde", "unstable-locales"] } -clap = { version = "4.5.4", features = ["derive"], optional = true } +clap = { version = "4.5.4", features = ["derive", "cargo"], optional = true } comrak = { version = "0.22.0", features = ["syntect", "shortcodes"], default-features = false } daggy = { version = "0.8.0", features = ["stable_dag"] } toml = "0.8.12" diff --git a/src/main.rs b/src/main.rs index f3c4c9c..8e4da77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ use ahash::AHashMap; +use clap::{arg, crate_version}; +use clap::{Parser, Subcommand}; use daggy::{stable_dag::StableDag, NodeIndex}; use glob::glob; use liquid::{object, Object}; @@ -20,9 +22,33 @@ use vox::{builds::Build, page::Page, templates::create_liquid_parser}; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; +#[derive(Parser)] +#[command(version, about, long_about = None)] +struct Cli { + #[command(subcommand)] + command: Option, +} +#[derive(Subcommand)] +enum Commands { + Build { + #[arg(short, long, default_value_t = false)] + watch: bool, + }, + Serve { + #[arg(short, long, default_value_t = true)] + watch: bool, + }, +} + #[tokio::main(flavor = "multi_thread")] async fn main() -> Result<(), Box> { tracing_subscriber::fmt().init(); + let cli = Cli::parse(); + match cli.command { + Some(Commands::Build { watch }) => build(watch).await?, + Some(Commands::Serve { watch }) => {} + None => println!("Vox {}", crate_version!()), + } Ok(()) }