Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 7579147

Browse files
author
Fredrik Grönqvist
committed
extracted table print
1 parent 71fc90e commit 7579147

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/main.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::fdns::Entry;
12
use std::fs;
23

34
use clap::{App, Arg};
@@ -91,24 +92,7 @@ fn main() {
9192
Ok(entries) => match matches.value_of("output").unwrap() {
9293
"json" => println!("{:#?}", serde_json::to_string(&entries).unwrap()),
9394
"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);
11296
}
11397
_ => unreachable!(),
11498
},
@@ -118,6 +102,27 @@ fn main() {
118102
}
119103
}
120104

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+
121126
fn read_csv(path: &str) -> Vec<std::string::String> {
122127
let content = fs::read_to_string(path).unwrap();
123128
content

0 commit comments

Comments
 (0)