Skip to content

Commit

Permalink
Persistence Checlk
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schildt <sebastian.schildt@de.bosch.com>
  • Loading branch information
SebastianSchildt committed Oct 12, 2024
1 parent f70153a commit 89f9943
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kuksa-persistence-provider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions kuksa-persistence-provider/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
41 changes: 41 additions & 0 deletions kuksa-persistence-provider/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf>,

/// 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!");
}

0 comments on commit 89f9943

Please sign in to comment.