diff --git a/Cargo.lock b/Cargo.lock index c1b8333..8d0e66d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,6 +15,54 @@ dependencies = [ "version_check", ] +[[package]] +name = "anstream" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -47,9 +95,10 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clafrica" -version = "0.3.1" +version = "0.4.0" dependencies = [ "clafrica-lib", + "clap", "enigo", "rdev", "rhai", @@ -60,7 +109,47 @@ dependencies = [ [[package]] name = "clafrica-lib" -version = "0.3.0" +version = "0.3.1" + +[[package]] +name = "clap" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +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]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "cocoa" @@ -77,6 +166,12 @@ dependencies = [ "objc", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "const-random" version = "0.1.15" @@ -263,6 +358,12 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "indexmap" version = "2.0.0" @@ -467,6 +568,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "2.0.33" @@ -527,6 +634,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "version_check" version = "0.9.4" @@ -580,6 +693,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/clafrica/Cargo.toml b/clafrica/Cargo.toml index 87249c7..92ace19 100644 --- a/clafrica/Cargo.toml +++ b/clafrica/Cargo.toml @@ -13,6 +13,7 @@ authors = ["Brady Fomegne "] [dependencies] clafrica-lib = { version = "0.3.0", path = "../clafrica-lib" } +clap = { version = "4.4.6", features = ["derive"] } enigo = "0.1.2" rdev = "0.5.2" rhai = "1.15.1" diff --git a/clafrica/src/main.rs b/clafrica/src/main.rs index 60dc342..060f4c9 100644 --- a/clafrica/src/main.rs +++ b/clafrica/src/main.rs @@ -1,21 +1,32 @@ use clafrica::{api, prelude::Config, run}; -use std::{env, path::Path, process}; +use clap::Parser; +use std::process; + +/// Clafrica CLI +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Args { + /// Path to the configuration file + config_file: std::path::PathBuf, + + /// Only verify if the configuration file is valid + #[arg(long, action)] + check: bool, +} fn main() { + let args = Args::parse(); let frontend = api::Console::default(); - let filename = env::args().nth(1).unwrap_or_else(|| { - eprintln!("Configuration file required"); - process::exit(1); - }); - - let conf = Config::from_file(Path::new(&filename)).unwrap_or_else(|err| { + let conf = Config::from_file(&args.config_file).unwrap_or_else(|err| { eprintln!("Problem parsing config file: {err}"); process::exit(1); }); - if let Err(e) = run(conf, frontend) { - eprintln!("Application error: {e}"); - process::exit(1); + if !args.check { + run(conf, frontend).unwrap_or_else(|e| { + eprintln!("Application error: {e}"); + process::exit(1); + }); } }