From ce6f5300fd86042a55be531d3d9d5c7c2dd97fcf Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Wed, 15 Nov 2023 21:15:53 -0700 Subject: [PATCH] Initial params loading --- Cargo.toml | 2 ++ params.toml | 5 +++++ src/main.rs | 20 ++++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 params.toml diff --git a/Cargo.toml b/Cargo.toml index 292fad3..8ba95fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.4.8", features = ["derive"]} +toml = "0.8.8" diff --git a/params.toml b/params.toml new file mode 100644 index 0000000..0d287a7 --- /dev/null +++ b/params.toml @@ -0,0 +1,5 @@ +[global_flow] +gen_decl = 0.4 +gen_subroutine = 0.3 +gen_typedef = 0.0 +gen_generation = 0.3 diff --git a/src/main.rs b/src/main.rs index e7a11a9..dd96a80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,19 @@ -fn main() { - println!("Hello, world!"); +use std::fs; +use std::path::PathBuf; +use clap::Parser; + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Args { + config: PathBuf, +} + +fn main() { + let args = Args::parse(); + let params_toml = fs::read_to_string(&args.config) + .expect("Failed to read parameters file into string") + .parse::() + .expect("Failed to parse TOML from parameters file"); + + println!("{}", params_toml["global_flow"]["gen_decl"]); }