Skip to content

Commit

Permalink
output data dictionary as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarzik committed Feb 16, 2024
1 parent 783fd2c commit b050990
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
49 changes: 47 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ description = "pcgtools: tools for reading PCgen PCC and LST data files"

[dependencies]
clap = { version = "4", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
extern crate clap;

use clap::Parser;
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
fs::File,
Expand All @@ -30,6 +31,7 @@ struct Args {
datadir: String,
}

#[derive(Serialize, Deserialize)]
enum PccTag {
Bool,
Date,
Expand All @@ -39,6 +41,7 @@ enum PccTag {
PccFile,
}

#[derive(Serialize, Deserialize)]
pub struct PccList {
_ident: String,
attrib: Vec<(String, String)>,
Expand All @@ -53,6 +56,7 @@ impl PccList {
}
}

#[derive(Serialize, Deserialize)]
pub enum PccDatum {
Text(String),
List(PccList),
Expand All @@ -67,11 +71,12 @@ impl PccDatum {
}
}

#[derive(Clone)]
#[derive(Clone, Serialize, Deserialize)]
pub struct PccConfig {
datadir: String,
}

#[derive(Serialize, Deserialize)]
pub struct Pcc {
config: PccConfig,
dict: HashMap<String, PccDatum>,
Expand Down Expand Up @@ -385,12 +390,7 @@ impl Pcc {

// display all data in data dictionary
pub fn display(&self) {
for (key, datum) in &self.dict {
match datum {
PccDatum::Text(textstr) => println!("{}={}", key, textstr),
_ => {}
}
}
println!("{}", serde_json::to_string_pretty(self).unwrap());
}
}

Expand Down

0 comments on commit b050990

Please sign in to comment.