From baa41fcd231ad6cc3f408d8de637729762354a7f Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 24 Sep 2023 09:11:14 +0200 Subject: [PATCH] c2rs: added clap command line arguments. --- Cargo.toml | 1 + src/bin/c2rs.rs | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5ab7cc..3f9c4b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ serde_derive = "1" serde_json = "1" quick-xml = { version = "0.30.0", features = [ "serialize" ] } tera = "1.8.0" +clap = { version = "4.4.5", features = ["derive"] } [dev-dependencies] config = "0.13" diff --git a/src/bin/c2rs.rs b/src/bin/c2rs.rs index 86793ab..29557fd 100644 --- a/src/bin/c2rs.rs +++ b/src/bin/c2rs.rs @@ -7,6 +7,21 @@ use quick_xml::de::from_str; use serde::Deserialize; use serde_derive::Deserialize; +use clap::Parser; + +/// Convert libzakform xml file to zakform rust code +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + /// libzakform xml input file + #[arg(short, long)] + input_file: String, + + /// zakform rust code file + #[arg(short, long)] + output_file: String, +} + #[derive(Default, Debug, Clone, PartialEq, Deserialize)] #[serde(default, rename = "zakform")] pub struct ZakForm { @@ -110,9 +125,9 @@ pub struct ZakFormElementRadioOption { } fn main() { - let formfile = env::args().nth(1).expect("no form file given"); + let args = Args::parse(); - let content = fs::read_to_string(formfile).expect("something went wrong reading the file"); + let content = fs::read_to_string(args.input_file).expect("something went wrong reading the file"); let form: ZakForm = from_str(&content).unwrap(); -- 2.49.0