From 89f9943ec5a1dcefe69369db1550a375fee38553 Mon Sep 17 00:00:00 2001 From: Sebastian Schildt Date: Sat, 12 Oct 2024 19:12:20 +0200 Subject: [PATCH] Persistence Checlk Signed-off-by: Sebastian Schildt --- kuksa-persistence-provider/Cargo.toml | 10 +++++++ kuksa-persistence-provider/config.json | 14 +++++++++ kuksa-persistence-provider/src/main.rs | 41 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 kuksa-persistence-provider/Cargo.toml create mode 100644 kuksa-persistence-provider/config.json create mode 100644 kuksa-persistence-provider/src/main.rs diff --git a/kuksa-persistence-provider/Cargo.toml b/kuksa-persistence-provider/Cargo.toml new file mode 100644 index 0000000..aea2063 --- /dev/null +++ b/kuksa-persistence-provider/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "kuksa-persistence-provider" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.5.20", features = ["derive"] } +tinyjson = "2.5.1" diff --git a/kuksa-persistence-provider/config.json b/kuksa-persistence-provider/config.json new file mode 100644 index 0000000..a257b22 --- /dev/null +++ b/kuksa-persistence-provider/config.json @@ -0,0 +1,14 @@ +{ + "restore-only": [ + "Vehicle.Speed", + "Vehicle.Engine.RPM" + ], + "restore-and-watch": [ + "Vehicle.D", + "Vehicle.X" + ], + "state-storage": { + "type": "file", + "path": "state.json" + } +} \ No newline at end of file diff --git a/kuksa-persistence-provider/src/main.rs b/kuksa-persistence-provider/src/main.rs new file mode 100644 index 0000000..44b8983 --- /dev/null +++ b/kuksa-persistence-provider/src/main.rs @@ -0,0 +1,41 @@ + +use std::path::PathBuf; +use clap::Parser; +use tinyjson::JsonValue; + +#[derive(Parser)] +#[command(version, about, long_about = None)] +struct CmdLine { + /// JSON file containing the configuration + #[arg(short, long, value_name = "FILE")] + config: Option, + + /// Turn debugging information on + #[arg(short, long, action = clap::ArgAction::Count)] + debug: u8, +} + +fn main() { + let args = CmdLine::parse(); + + let config = args.config.unwrap_or_else(|| PathBuf::from("config.json")); + + //Check config exists + if !config.exists() { + eprintln!("Error: Can not find configuration at {}", config.display()); + std::process::exit(1); + } + + println!("Reading configuration from: {}", config.display()); + // Reading configuration file into a string + let config_str = std::fs::read_to_string(config).unwrap(); + + println!("Configuration: {}", config_str); + + let parsed: JsonValue = config_str.parse().unwrap(); + println!("Parsed: {:?}", parsed); + + + + println!("Hello, world!"); +}