mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
Merge pull request #215 from rustic-rs/display-snapshot-groups
Nicer display for SnapshotGroups
This commit is contained in:
commit
983e71b662
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user