@@ -45,13 +45,22 @@ fn main() -> noargs::Result<()> {
4545 let client = EpmdClient :: new ( stream) ;
4646
4747 let names = client. get_names ( ) . await ?;
48- let result = serde_json:: json!(
49- names
50- . into_iter( )
51- . map( |( name, port) | serde_json:: json!( { "name" : name, "port" : port} ) )
52- . collect:: <Vec <_>>( )
53- ) ;
54- println ! ( "{}" , serde_json:: to_string_pretty( & result) ?) ;
48+ let result = nojson:: json ( |f| {
49+ f. set_indent_size ( 2 ) ;
50+ f. set_spacing ( true ) ;
51+ f. array ( |f| {
52+ for ( name, port) in & names {
53+ f. element ( nojson:: json ( |f| {
54+ f. object ( |f| {
55+ f. member ( "name" , name. as_str ( ) ) ?;
56+ f. member ( "port" , * port)
57+ } )
58+ } ) ) ?;
59+ }
60+ Ok ( ( ) )
61+ } )
62+ } ) ;
63+ println ! ( "{result}" ) ;
5564 Ok :: < ( ) , Box < dyn std:: error:: Error > > ( ( ) )
5665 } ) ?;
5766 } else if noargs:: cmd ( "dump" )
@@ -94,16 +103,36 @@ fn main() -> noargs::Result<()> {
94103 let client = EpmdClient :: new ( stream) ;
95104
96105 let node_info = client. get_node ( & node) . await ?. ok_or ( "node not found" ) ?;
97- let result = serde_json:: json!( {
98- "name" : node_info. name,
99- "port" : node_info. port,
100- "node_type" : format!( "{:?} ({})" , node_info. node_type, u8 :: from( node_info. node_type) ) ,
101- "protocol" : format!( "{:?} ({})" , node_info. protocol, u8 :: from( node_info. protocol) ) ,
102- "highest_version" : node_info. highest_version,
103- "lowest_version" : node_info. lowest_version,
104- "extra" : node_info. extra
106+ let result = nojson:: json ( |f| {
107+ f. set_indent_size ( 2 ) ;
108+ f. set_spacing ( true ) ;
109+ f. object ( |f| {
110+ f. member ( "name" , node_info. name . as_str ( ) ) ?;
111+ f. member ( "port" , node_info. port ) ?;
112+ f. member (
113+ "node_type" ,
114+ format ! (
115+ "{:?} ({})" ,
116+ node_info. node_type,
117+ u8 :: from( node_info. node_type)
118+ )
119+ . as_str ( ) ,
120+ ) ?;
121+ f. member (
122+ "protocol" ,
123+ format ! (
124+ "{:?} ({})" ,
125+ node_info. protocol,
126+ u8 :: from( node_info. protocol)
127+ )
128+ . as_str ( ) ,
129+ ) ?;
130+ f. member ( "highest_version" , node_info. highest_version ) ?;
131+ f. member ( "lowest_version" , node_info. lowest_version ) ?;
132+ f. member ( "extra" , node_info. extra . as_slice ( ) )
133+ } )
105134 } ) ;
106- println ! ( "{}" , serde_json :: to_string_pretty ( & result ) ? ) ;
135+ println ! ( "{result}" ) ;
107136 Ok :: < ( ) , Box < dyn std:: error:: Error > > ( ( ) )
108137 } ) ?;
109138 } else if noargs:: cmd ( "kill" )
@@ -122,8 +151,12 @@ fn main() -> noargs::Result<()> {
122151 let client = EpmdClient :: new ( stream) ;
123152
124153 let result = client. kill ( ) . await ?;
125- let result = serde_json:: json!( { "result" : result } ) ;
126- println ! ( "{}" , serde_json:: to_string_pretty( & result) ?) ;
154+ let result = nojson:: json ( |f| {
155+ f. set_indent_size ( 2 ) ;
156+ f. set_spacing ( true ) ;
157+ f. object ( |f| f. member ( "result" , result. as_str ( ) ) )
158+ } ) ;
159+ println ! ( "{result}" ) ;
127160 Ok :: < ( ) , Box < dyn std:: error:: Error > > ( ( ) )
128161 } ) ?;
129162 } else if noargs:: cmd ( "register" )
@@ -161,10 +194,12 @@ fn main() -> noargs::Result<()> {
161194 NodeEntry :: new ( & name, port)
162195 } ;
163196 let ( _, creation) = client. register ( node) . await ?;
164- let result = serde_json:: json!( {
165- "creation" : creation. get( )
197+ let result = nojson:: json ( |f| {
198+ f. set_indent_size ( 2 ) ;
199+ f. set_spacing ( true ) ;
200+ f. object ( |f| f. member ( "creation" , creation. get ( ) ) )
166201 } ) ;
167- println ! ( "{}" , serde_json :: to_string_pretty ( & result ) ? ) ;
202+ println ! ( "{result}" ) ;
168203 Ok :: < ( ) , Box < dyn std:: error:: Error > > ( ( ) )
169204 } ) ?;
170205 } else if let Some ( help) = args. finish ( ) ? {
0 commit comments