11mod document;
22use crate :: document:: Document ;
3- use serde_hjson:: Value ;
3+ use serde_yaml:: Value ;
4+ use std:: borrow:: Cow ;
45use std:: collections:: HashMap ;
56use std:: fs:: File ;
67use 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
6974fn 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
9198pub 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