From ae174b6dfcb8fa4e37bcf67c34ab5598cedbd6c1 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Tue, 28 May 2024 21:58:30 +0200 Subject: [PATCH] feat(commands): backup: Add option --long --- src/commands/backup.rs | 21 ++++++++++++++++++--- src/commands/snapshots.rs | 6 ++++-- tests/show-config-fixtures/empty.txt | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/commands/backup.rs b/src/commands/backup.rs index 54e2ab30c..69c5c9c39 100644 --- a/src/commands/backup.rs +++ b/src/commands/backup.rs @@ -3,13 +3,14 @@ use std::path::PathBuf; use crate::{ - commands::{get_repository, init::init, open_repository}, - helpers::bytes_size_to_string, + commands::{get_repository, init::init, open_repository, snapshots::fill_table}, + helpers::{bold_cell, bytes_size_to_string, table}, status_err, Application, RUSTIC_APP, }; use abscissa_core::{Command, Runnable, Shutdown}; use anyhow::{bail, Context, Result}; +use comfy_table::Cell; use log::{debug, info, warn}; use merge::Merge; use serde::{Deserialize, Serialize}; @@ -62,9 +63,14 @@ pub struct BackupCmd { #[merge(strategy = merge::bool::overwrite_false)] json: bool, - /// Don't show any output + /// Show detailed information about generated snapshot #[clap(long, conflicts_with = "json")] #[merge(strategy = merge::bool::overwrite_false)] + long: bool, + + /// Don't show any output + #[clap(long, conflicts_with_all = ["json", "long"])] + #[merge(strategy = merge::bool::overwrite_false)] quiet: bool, /// Initialize repository, if it doesn't exist yet @@ -237,6 +243,15 @@ impl BackupCmd { if opts.json { let mut stdout = std::io::stdout(); serde_json::to_writer_pretty(&mut stdout, &snap)?; + } else if opts.long { + let mut table = table(); + + let add_entry = |title: &str, value: String| { + _ = table.add_row([bold_cell(title), Cell::new(value)]); + }; + fill_table(&snap, add_entry); + + println!("{table}"); } else if !opts.quiet { let summary = snap.summary.unwrap(); println!( diff --git a/src/commands/snapshots.rs b/src/commands/snapshots.rs index 1a6bbc2e5..9361c234b 100644 --- a/src/commands/snapshots.rs +++ b/src/commands/snapshots.rs @@ -161,8 +161,10 @@ pub fn snap_to_table(sn: &SnapshotFile, count: usize) -> [String; 9] { pub fn fill_table(snap: &SnapshotFile, mut add_entry: impl FnMut(&str, String)) { add_entry("Snapshot", snap.id.to_hex().to_string()); // note that if original was not set, it is set to snap.id by the load process - if snap.original != Some(snap.id) { - add_entry("Original ID", snap.original.unwrap().to_hex().to_string()); + if let Some(original) = snap.original { + if original != snap.id { + add_entry("Original ID", original.to_hex().to_string()); + } } add_entry("Time", snap.time.format("%Y-%m-%d %H:%M:%S").to_string()); add_entry("Generated by", snap.program_version.clone()); diff --git a/tests/show-config-fixtures/empty.txt b/tests/show-config-fixtures/empty.txt index 5f2bb2413..5ed6c4d33 100644 --- a/tests/show-config-fixtures/empty.txt +++ b/tests/show-config-fixtures/empty.txt @@ -30,6 +30,7 @@ with-atime = false ignore-devid = false no-scan = false json = false +long = false quiet = false init = false skip-identical-parent = false