add basic schema struct

This commit is contained in:
Brian Hicks 2024-04-04 05:48:07 -05:00
parent 80bed6eb8d
commit a130a40620
No known key found for this signature in database
GPG Key ID: C4F324B9CAAB0D50
4 changed files with 27 additions and 1 deletions

2
Cargo.lock generated
View File

@ -220,6 +220,8 @@ dependencies = [
"color-eyre",
"eyre",
"jtd",
"serde",
"serde_json",
"tracing",
]

View File

@ -10,4 +10,6 @@ clap = { version = "4.5.4", features = ["derive"] }
color-eyre = "0.6.3"
eyre = "0.6.12"
jtd = "0.3.1"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
tracing = "0.1.40"

View File

@ -1,5 +1,8 @@
mod schema;
use clap::Parser;
use eyre::Result;
use color_eyre::Result;
use eyre::WrapErr;
use std::path::PathBuf;
#[derive(Debug, Parser)]
@ -11,6 +14,10 @@ struct Cli {
impl Cli {
fn run(&self) -> Result<()> {
println!("{self:#?}");
let schema = schema::Schema::from_fs(&self.source).wrap_err("could not read schema")?;
println!("{schema:#?}");
Ok(())
}
}

15
src/schema.rs Normal file
View File

@ -0,0 +1,15 @@
use color_eyre::Result;
use eyre::WrapErr;
use serde::Deserialize;
use std::path::Path;
#[derive(Debug, Deserialize)]
pub struct Schema {}
impl Schema {
pub fn from_fs(path: &Path) -> Result<Schema> {
let bytes = std::fs::read(path).wrap_err_with(|| format!("could not read {path:?}"))?;
serde_json::from_slice(&bytes)
.wrap_err_with(|| format!("could not read schema from {path:?}"))
}
}