Skip to content

Commit 63f20c9

Browse files
committed
Switch to yaml for actiondoc
1 parent 02b7f93 commit 63f20c9

File tree

4 files changed

+55
-82
lines changed

4 files changed

+55
-82
lines changed

docbuilder/Cargo.lock

Lines changed: 22 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docbuilder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
serde-hjson = { version = "0.9.1", default-features = false }
10+
serde_yaml = "0.8.17"

docbuilder/src/document.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ fn render_list(inp: Vec<String>) -> String {
9494
fn render_link_list(inp: Vec<String>, linklist: &HashMap<&'static str, &'static str>) -> String {
9595
inp.into_iter()
9696
.map(|v| {
97+
println!("looking for: {}", v);
9798
format!("- [{}]({})\n", v, linklist.get(v.as_str()).unwrap())
9899
.chars()
99100
.collect::<Vec<_>>()

docbuilder/src/main.rs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod document;
22
use crate::document::Document;
3-
use serde_hjson::Value;
3+
use serde_yaml::Value;
4+
use std::borrow::Cow;
45
use std::collections::HashMap;
56
use std::fs::File;
67
use std::io::Write;
@@ -16,7 +17,7 @@ macro_rules! get_str_array {
1617
($in:expr, $name:expr) => {
1718
$in.get($name)
1819
.unwrap()
19-
.as_array()
20+
.as_sequence()
2021
.unwrap()
2122
.iter()
2223
.map(|v| v.as_str().unwrap().to_owned())
@@ -33,21 +34,25 @@ fn main() {
3334
let output = Command::new("cat").arg("actions.jsonc").output().unwrap();
3435
let output = String::from_utf8_lossy(&output.stdout);
3536
let _rmfile = Command::new("rm").arg("actions.jsonc").output().unwrap();
36-
let json: Value = serde_hjson::from_str(&output).unwrap();
37-
let json = json.as_array().unwrap();
3837

3938
// now parse it
39+
parse_into_actiondoc(output)
40+
}
41+
42+
fn parse_into_actiondoc(output: Cow<'_, str>) {
43+
let yml: Value = serde_yaml::from_str(&output).unwrap();
44+
let yml = yml.as_sequence().unwrap();
4045
let mut actlist = Vec::new();
4146
let mut docs = Vec::new();
4247
let linklist = init_type_linklist();
43-
for item in json {
44-
let obj = item.as_object().unwrap();
45-
let name = getstr!(obj, "name");
46-
let complexity = getstr!(obj, "complexity");
47-
let accept_ty = get_str_array!(obj, "accept");
48-
let return_ty = get_str_array!(obj, "return");
49-
let syntax = get_str_array!(obj, "syntax");
50-
let description = getstr!(obj, "desc");
48+
for map in yml.iter() {
49+
let name = getstr!(map, "name");
50+
let complexity = getstr!(map, "complexity");
51+
println!("{:?}", map.get("accept").unwrap());
52+
let accept_ty = get_str_array!(map, "accept");
53+
let return_ty = get_str_array!(map, "return");
54+
let syntax = get_str_array!(map, "syntax");
55+
let description = getstr!(map, "desc");
5156
actlist.push(name.clone());
5257
let doc = Document::new(name, complexity, accept_ty, return_ty, description, syntax);
5358
docs.push(doc);
@@ -67,13 +72,15 @@ fn main() {
6772
}
6873

6974
fn gen_action_list(list: Vec<String>) -> String {
70-
let mut act = "
71-
---
72-
id: all-actions
73-
title: Index of actions
74-
---
75-
Skytable currently supports the following actions:
76-
"
75+
let mut act = "\
76+
---
77+
id: all-actions
78+
title: Index of actions
79+
---
80+
81+
Skytable currently supports the following actions:
82+
83+
"
7784
.to_owned();
7885
let linklist: String = list
7986
.into_iter()
@@ -90,6 +97,7 @@ fn gen_action_list(list: Vec<String>) -> String {
9097

9198
pub fn init_type_linklist() -> HashMap<&'static str, &'static str> {
9299
let mut hm = HashMap::new();
100+
hm.insert("Rcode 0", "protocol/response-codes");
93101
hm.insert("Rcode 1", "protocol/response-codes");
94102
hm.insert("Rcode 2", "protocol/response-codes");
95103
hm.insert("Rcode 3", "protocol/response-codes");
@@ -101,7 +109,10 @@ pub fn init_type_linklist() -> HashMap<&'static str, &'static str> {
101109
hm.insert("Rcode 9", "protocol/response-codes");
102110
hm.insert("Error String", "protocol/errors#table-of-errors");
103111
hm.insert("err-snapshot-busy", "protocol/errors/#table-of-errors");
104-
hm.insert("err-invalid-snapshot-name", "protocol/errors/#table-of-errors");
112+
hm.insert(
113+
"err-invalid-snapshot-name",
114+
"protocol/errors/#table-of-errors",
115+
);
105116
hm.insert("err-snapshot-disabled", "protocol/errors/#table-of-errors");
106117
hm.insert("AnyArray", "protocol/data-types#any-array");
107118
hm.insert("Flat Array", "protocol/data-types#flat-array");

0 commit comments

Comments
 (0)