Add very basic CLI.

This commit is contained in:
Tom Alexander 2023-10-18 19:26:04 -04:00
parent 7418d4fd81
commit 1b189cf15c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 118 additions and 7 deletions

55
Cargo.lock generated
View File

@ -102,6 +102,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive",
] ]
[[package]] [[package]]
@ -113,7 +114,18 @@ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
"clap_lex", "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]] [[package]]
@ -134,6 +146,12 @@ version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.3.3" version = "0.3.3"
@ -212,6 +230,24 @@ version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" 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]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.23" version = "0.1.23"
@ -228,10 +264,15 @@ dependencies = [
] ]
[[package]] [[package]]
name = "strsim" name = "syn"
version = "0.10.0" version = "2.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "tokio" name = "tokio"
@ -244,6 +285,12 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]] [[package]]
name = "utf8parse" name = "utf8parse"
version = "0.2.1" version = "0.2.1"

View File

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [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" organic = "0.1.12"
tokio = { version = "1.30.0", default-features = false, features = ["rt", "rt-multi-thread"] } tokio = { version = "1.30.0", default-features = false, features = ["rt", "rt-multi-thread"] }

View File

@ -1,3 +1,66 @@
fn main() { use clap::Args;
println!("Hello, world!"); use clap::Parser;
use clap::Subcommand;
use std::path::PathBuf;
use std::process::ExitCode;
fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
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<ExitCode, Box<dyn std::error::Error>> {
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,
} }