1
+ use crate :: fdns:: Entry ;
1
2
use std:: fs;
2
3
3
4
use clap:: { App , Arg } ;
@@ -91,24 +92,7 @@ fn main() {
91
92
Ok ( entries) => match matches. value_of ( "output" ) . unwrap ( ) {
92
93
"json" => println ! ( "{:#?}" , serde_json:: to_string( & entries) . unwrap( ) ) ,
93
94
"table" => {
94
- let mut table = Table :: new ( ) ;
95
- table. add_row ( Row :: new ( vec ! [
96
- Cell :: new( "NAME" ) ,
97
- Cell :: new( "VALUE" ) ,
98
- Cell :: new( "TYPE" ) ,
99
- Cell :: new( "TIMESTAMP" ) ,
100
- ] ) ) ;
101
-
102
- for entry in entries {
103
- table. add_row ( Row :: new ( vec ! [
104
- Cell :: new( & entry. name) ,
105
- Cell :: new( & entry. value) ,
106
- Cell :: new( & entry. kind) ,
107
- Cell :: new( & entry. timestamp) ,
108
- ] ) ) ;
109
- }
110
-
111
- table. printstd ( ) ;
95
+ print_as_table ( entries) ;
112
96
}
113
97
_ => unreachable ! ( ) ,
114
98
} ,
@@ -118,6 +102,27 @@ fn main() {
118
102
}
119
103
}
120
104
105
+ fn print_as_table ( entries : Vec < Entry > ) {
106
+ let mut table = Table :: new ( ) ;
107
+ table. add_row ( Row :: new ( vec ! [
108
+ Cell :: new( "NAME" ) ,
109
+ Cell :: new( "VALUE" ) ,
110
+ Cell :: new( "TYPE" ) ,
111
+ Cell :: new( "TIMESTAMP" ) ,
112
+ ] ) ) ;
113
+
114
+ for entry in entries {
115
+ table. add_row ( Row :: new ( vec ! [
116
+ Cell :: new( & entry. name) ,
117
+ Cell :: new( & entry. value) ,
118
+ Cell :: new( & entry. kind) ,
119
+ Cell :: new( & entry. timestamp) ,
120
+ ] ) ) ;
121
+ }
122
+
123
+ table. printstd ( ) ;
124
+ }
125
+
121
126
fn read_csv ( path : & str ) -> Vec < std:: string:: String > {
122
127
let content = fs:: read_to_string ( path) . unwrap ( ) ;
123
128
content
0 commit comments