progress: add format variants

for iterating over a single group, or iterating just on the group level

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2020-11-30 16:27:20 +01:00 committed by Dietmar Maurer
parent fc8920e35d
commit f867ef9c4a

View File

@ -795,14 +795,32 @@ impl StoreProgress {
impl std::fmt::Display for StoreProgress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{:.2}% ({} of {} groups, {} of {} group snapshots)",
self.percentage() * 100.0,
self.done_groups,
self.total_groups,
self.done_snapshots,
self.group_snapshots,
)
if self.group_snapshots == 0 {
write!(
f,
"{:.2}% ({} of {} groups)",
self.percentage() * 100.0,
self.done_groups,
self.total_groups,
)
} else if self.total_groups == 1 {
write!(
f,
"{:.2}% ({} of {} snapshots)",
self.percentage() * 100.0,
self.done_snapshots,
self.group_snapshots,
)
} else {
write!(
f,
"{:.2}% ({} of {} groups, {} of {} group snapshots)",
self.percentage() * 100.0,
self.done_groups,
self.total_groups,
self.done_snapshots,
self.group_snapshots,
)
}
}
}