prettify output

This commit is contained in:
bauen1
2020-05-09 14:57:23 +02:00
parent 54a9435bb5
commit e85f4c4ab2
3 changed files with 62 additions and 1 deletions
Generated
+47
View File
@@ -20,6 +20,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "bitflags"
version = "1.2.1"
@@ -32,6 +38,17 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e54f7b7a46d7b183eb41e2d82965261fa8a1597c68b50aced268ee1fc70272d"
[[package]]
name = "chrono"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
dependencies = [
"num-integer",
"num-traits",
"time",
]
[[package]]
name = "cidr"
version = "0.1.0"
@@ -61,6 +78,7 @@ dependencies = [
name = "dn42-roagen"
version = "0.1.0"
dependencies = [
"chrono",
"cidr",
"structopt",
]
@@ -95,6 +113,25 @@ version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
[[package]]
name = "num-integer"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
dependencies = [
"autocfg",
]
[[package]]
name = "proc-macro-error"
version = "1.0.2"
@@ -206,6 +243,16 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "time"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "unicode-segmentation"
version = "1.6.0"
+1
View File
@@ -9,3 +9,4 @@ edition = "2018"
[dependencies]
structopt = "0.3.14"
cidr = "0.1.0"
chrono = "0.4.11"
+14 -1
View File
@@ -6,6 +6,8 @@ use std::convert::TryFrom;
use std::str::FromStr;
use std::path::PathBuf;
use std::fmt;
use std::process::Command;
use chrono::prelude::*;
#[derive(Debug,PartialEq)]
enum ROAFilterAction {
@@ -168,7 +170,12 @@ fn roa_filter(roas: Vec<ROA>, filters: Vec<ROAFilter>) -> Vec<ROA> {
}
fn roa_to_output(roas: Vec<ROA>) -> String {
roas.into_iter().map(|roa| roa.to_string()).collect::<Vec<String>>().join("\n")
let mut roas = Vec::from(roas);
roas.sort_by(|a,b| a.route.first_address().cmp(&b.route.first_address()));
roas.into_iter()
.into_iter()
.map(|roa| roa.to_string())
.collect::<Vec<String>>().join("\n")
}
#[derive(StructOpt)]
@@ -189,6 +196,12 @@ fn main() {
let roa_ip4 = parse_roa(data_path.join("route"));
let roa_ip6 = parse_roa(data_path.join("route6"));
println!("#");
println!("# dn42-roagen: simple dn42 roa generator");
println!("# generated on: {}", Utc::now());
print!("# commit: {}", String::from_utf8_lossy(&Command::new("git").arg("-C").arg(args.registry_path).arg("log").arg("-1").arg("--format=%H").output().expect("failed to determine git commit").stdout));
println!("#");
println!("{}\n", roa_to_output(roa_filter(roa_ip4, roa_filter_ip4)));
println!("{}\n", roa_to_output(roa_filter(roa_ip6, roa_filter_ip6)));
}