Skip to content

Commit

Permalink
feat(catalog): add filesize to --details columns
Browse files Browse the repository at this point in the history
  • Loading branch information
graelo committed Aug 18, 2022
1 parent 809214a commit a9285e4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ thiserror = "1"
nom = "7"
regex = "1.4"
itertools = "0.10.3" # waiting for https://doc.rust-lang.org/std/primitive.slice.html#method.group_by
si-scale = "0.2"

futures = "0.3"
async-std = { version = "1", features = ["unstable"] }
Expand Down
4 changes: 2 additions & 2 deletions src/management/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub enum BackupStatus {
impl fmt::Display for BackupStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BackupStatus::Retainable => write!(f, "retainable"),
BackupStatus::Purgeable => write!(f, "purgeable"),
BackupStatus::Retainable => write!(f, "{:12}", "retainable"),
BackupStatus::Purgeable => write!(f, "{:12}", "purgeable"),
}
}
}
10 changes: 7 additions & 3 deletions src/management/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use async_std::{fs, task};
use chrono::{Duration, Local, NaiveDateTime};
use futures::future::join_all;
use regex::Regex;
use si_scale::helpers::bytes2;

use crate::management::{
archive::v1,
Expand Down Expand Up @@ -284,8 +285,8 @@ impl Catalog {
if details_flag {
// Table header
println!(
"{:4} {:32} {:17} {:12} {:8} {:8}",
"", "NAME", "CREATED", "STATUS", "VERSION", "CONTENT"
"{:4} {:32} {:17} {:12} {:11} {:8} {:8}",
"", "NAME", "CREATED", "STATUS", "FILESIZE", "VERSION", "CONTENT"
);

// Read all metadata concurrently
Expand All @@ -304,6 +305,9 @@ impl Catalog {
iter::zip(indices, iter::zip(statuses, metadatas))
{
let filename = backup.filepath.file_name().unwrap().to_string_lossy();
let filesize = fs::metadata(backup.filepath.as_path()).await.unwrap().len();
let filesize = bytes2(filesize as f64);

let color = match status {
BackupStatus::Purgeable => yellow,
BackupStatus::Retainable => green,
Expand All @@ -314,7 +318,7 @@ impl Catalog {
let version = &metadata.version;

println!(
"{index:3}. {color}{filename:32}{reset} {time_ago:17} {color}{status:12}{reset} {version:8} {overview:8}"
"{index:3}. {color}{filename:32}{reset} {time_ago:17} {color}{status:12}{reset} {filesize:11} {version:8} {overview:8}"
);
}
} else {
Expand Down

0 comments on commit a9285e4

Please sign in to comment.