From 23440482d42651525afc81cf6dbc49338a72a553 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 20 Oct 2020 11:43:48 +0200 Subject: [PATCH] proxmox-backup-client: use HumanByte to render snapshot size --- src/bin/proxmox-backup-client.rs | 2 +- src/tools/format.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index ffe5b3dd..4bb05bd1 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -510,7 +510,7 @@ async fn list_snapshots(param: Value) -> Result { .sortby("backup-id", false) .sortby("backup-time", false) .column(ColumnConfig::new("backup-id").renderer(render_snapshot_path).header("snapshot")) - .column(ColumnConfig::new("size")) + .column(ColumnConfig::new("size").renderer(tools::format::render_bytes_human_readable)) .column(ColumnConfig::new("files").renderer(render_files)) ; diff --git a/src/tools/format.rs b/src/tools/format.rs index c3aa791b..8fe6aa82 100644 --- a/src/tools/format.rs +++ b/src/tools/format.rs @@ -50,6 +50,19 @@ pub fn render_bool_with_default_true(value: &Value, _record: &Value) -> Result Result { + if value.is_null() { return Ok(String::new()); } + let text = match value.as_u64() { + Some(bytes) => { + HumanByte::from(bytes).to_string() + } + None => { + value.to_string() + } + }; + Ok(text) +} + pub struct HumanByte { b: usize, }