From c511e5a4d8a4fda55d3d1f1fe6a162683d4d9e6a Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 15 Feb 2024 08:48:26 +0100 Subject: [PATCH] add argument parser + parse config arg, Fixes #5 --- Cargo.lock | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- src/main.rs | 14 +++++++++++--- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62725cd..3ca4390 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,6 +104,46 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + [[package]] name = "colorchoice" version = "1.0.0" @@ -230,6 +270,12 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hoot" version = "0.1.3" @@ -477,6 +523,7 @@ dependencies = [ name = "risp" version = "0.1.0" dependencies = [ + "clap", "env_logger", "log", "pretty_assertions", @@ -620,6 +667,12 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + [[package]] name = "subtle" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index c0c705c..51bdb91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ env_logger = "0.11" log = "0.4" tqdm = "0.6" toml = "0.8" - +clap = { version = "4.5.0", features = ["derive"] } [dev-dependencies] pretty_assertions = "1.4" diff --git a/src/main.rs b/src/main.rs index ffd1b4c..414d9ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,19 @@ +use clap::{command, Parser}; use risp::law::Law; +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +struct Args { + /// Path to the config of a law text + #[arg(short, long)] + config: String, +} + fn main() { env_logger::init(); - let config_path = "./data/configs/stgb.toml"; - - let law = Law::from_config(config_path).unwrap(); + let args = Args::parse(); + let law = Law::from_config(&args.config).unwrap(); law.to_md(); }