Skip to content

Commit

Permalink
fix(cli): Use zip_longest when showing a diff of node changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa-tomic committed Jun 6, 2023
1 parent da0f535 commit db04589
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions rs/decentralization/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod nakamoto;
pub mod network;
use colored::Colorize;
use itertools::Itertools;
use itertools::{EitherOrBoth::*, Itertools};
use std::collections::{BTreeMap, HashMap};
use std::fmt::{Display, Formatter};

Expand Down Expand Up @@ -165,9 +165,25 @@ impl Display for SubnetChangeResponse {
}

writeln!(f, "{}", table)?;
self.added.iter().zip(self.removed.iter()).for_each(|(a, r)| {
writeln!(f, "{}{}", format!(" - {}", r).red(), format!(" + {}", a).green()).expect("write failed");
});
for pair in self.added.iter().zip_longest(self.removed.iter()) {
match pair {
Both(a, r) => {
writeln!(f, "{}{}", format!(" - {}", r).red(), format!(" + {}", a).green())
.expect("write failed");
}
Left(a) => {
writeln!(
f,
" {}",
format!(" + {}", a).green()
)
.expect("write failed");
}
Right(r) => {
writeln!(f, "{}", format!(" - {}", r).red()).expect("write failed");
}
}
}
writeln!(f)?;

if let Some(comment) = &self.comment {
Expand Down

0 comments on commit db04589

Please sign in to comment.