Merge pull request #215 from rustic-rs/display-snapshot-groups

Nicer display for SnapshotGroups
This commit is contained in:
aawsome 2022-09-16 14:57:31 +02:00 committed by GitHub
commit 983e71b662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

View File

@ -84,7 +84,7 @@ pub(super) async fn execute(
for (group, mut snapshots) in groups {
if !group.is_empty() {
println!("snapshots for {:?}", group);
println!("snapshots for {group}");
}
snapshots.sort_unstable_by(|sn1, sn2| sn1.cmp(sn2).reverse());
let latest_time = snapshots[0].time;

View File

@ -79,7 +79,7 @@ pub(super) async fn execute(
for (group, mut snapshots) in groups {
if !group.is_empty() {
println!("\nsnapshots for {:?}", group);
println!("\nsnapshots for {group}");
}
snapshots.sort_unstable();
let count = snapshots.len();

View File

@ -1,5 +1,6 @@
use std::cmp::Ordering;
use std::fmt;
use std::str::FromStr;
use std::{cmp::Ordering, fmt::Display};
use anyhow::{anyhow, bail, Result};
use chrono::{DateTime, Local};
@ -366,6 +367,25 @@ pub struct SnapshotGroup {
tags: Option<StringList>,
}
impl Display for SnapshotGroup {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut out = Vec::new();
if let Some(host) = &self.hostname {
out.push(format!("host [{host}]"));
}
if let Some(paths) = &self.paths {
out.push(format!("paths [{paths}]"));
}
if let Some(tags) = &self.tags {
out.push(format!("tags [{tags}]"));
}
write!(f, "({})", out.join(", "))?;
Ok(())
}
}
impl SnapshotGroup {
pub fn from_sn(sn: &SnapshotFile, crit: &SnapshotGroupCriterion) -> Self {
Self {
@ -390,6 +410,13 @@ impl FromStr for StringList {
}
}
impl Display for StringList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0.join(","))?;
Ok(())
}
}
impl StringList {
pub fn contains(&self, s: &String) -> bool {
self.0.contains(s)