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

Commit

Permalink
extracted table print
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Grönqvist committed Mar 2, 2021
1 parent 71fc90e commit 7579147
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::fdns::Entry;
use std::fs;

use clap::{App, Arg};
Expand Down Expand Up @@ -91,24 +92,7 @@ fn main() {
Ok(entries) => match matches.value_of("output").unwrap() {
"json" => println!("{:#?}", serde_json::to_string(&entries).unwrap()),
"table" => {
let mut table = Table::new();
table.add_row(Row::new(vec![
Cell::new("NAME"),
Cell::new("VALUE"),
Cell::new("TYPE"),
Cell::new("TIMESTAMP"),
]));

for entry in entries {
table.add_row(Row::new(vec![
Cell::new(&entry.name),
Cell::new(&entry.value),
Cell::new(&entry.kind),
Cell::new(&entry.timestamp),
]));
}

table.printstd();
print_as_table(entries);
}
_ => unreachable!(),
},
Expand All @@ -118,6 +102,27 @@ fn main() {
}
}

fn print_as_table(entries: Vec<Entry>) {
let mut table = Table::new();
table.add_row(Row::new(vec![
Cell::new("NAME"),
Cell::new("VALUE"),
Cell::new("TYPE"),
Cell::new("TIMESTAMP"),
]));

for entry in entries {
table.add_row(Row::new(vec![
Cell::new(&entry.name),
Cell::new(&entry.value),
Cell::new(&entry.kind),
Cell::new(&entry.timestamp),
]));
}

table.printstd();
}

fn read_csv(path: &str) -> Vec<std::string::String> {
let content = fs::read_to_string(path).unwrap();
content
Expand Down

0 comments on commit 7579147

Please sign in to comment.