From 1b189cf15c29bf57638bef77eaa6f632404f52ce Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 18 Oct 2023 19:26:04 -0400 Subject: [PATCH] Add very basic CLI. --- Cargo.lock | 55 +++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 3 ++- src/main.rs | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 118 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bbb68dc..d128ef8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,6 +102,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", + "clap_derive", ] [[package]] @@ -113,7 +114,18 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -134,6 +146,12 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.3" @@ -212,6 +230,24 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +[[package]] +name = "proc-macro2" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -228,10 +264,15 @@ dependencies = [ ] [[package]] -name = "strsim" -version = "0.10.0" +name = "syn" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] name = "tokio" @@ -244,6 +285,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 2cd1c57..f871973 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = "4.4.6" +# TODO: maybe error-context, suggestions, usage | env +clap = { version = "4.4.6", default-features = false, features = ["std", "color", "help", "derive"] } organic = "0.1.12" tokio = { version = "1.30.0", default-features = false, features = ["rt", "rt-multi-thread"] } diff --git a/src/main.rs b/src/main.rs index e7a11a9..040230e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,66 @@ -fn main() { - println!("Hello, world!"); +use clap::Args; +use clap::Parser; +use clap::Subcommand; +use std::path::PathBuf; +use std::process::ExitCode; + +fn main() -> Result> { + let rt = tokio::runtime::Runtime::new()?; + rt.block_on(async { + let main_body_result = main_body().await; + main_body_result + }) +} + +async fn main_body() -> Result> { + let args = Cli::parse(); + match args.command { + Commands::Init(_args) => {} + Commands::Build(_args) => {} + Commands::AddPost(_args) => {} + }; + Ok(ExitCode::SUCCESS) +} + +#[derive(Parser, Debug)] +#[command(name = "Writer")] +#[command(version = env!("CARGO_PKG_VERSION"))] +#[command(about = "Generate a static site.", long_about = None)] +#[command(propagate_version = true)] +struct Cli { + #[command(subcommand)] + command: Commands, +} + +#[derive(Subcommand, Debug)] +enum Commands { + /// Initialize an empty website folder. + Init(InitArgs), + + /// Build the static site. + Build(BuildArgs), + + /// Add a blog post to the site. + AddPost(BuildArgs), +} + +#[derive(Args, Debug)] +struct InitArgs { + /// Path where you want the initial writer structure to be located. + #[arg(short, long)] + path: PathBuf, +} + +#[derive(Args, Debug)] +struct BuildArgs { + /// Path to the writer config file. + #[arg(short, long)] + config: PathBuf, +} + +#[derive(Args, Debug)] +struct AddPostArgs { + /// Path to the writer config file. + #[arg(short, long)] + config: PathBuf, }