Skip to content

Commit 959c057

Browse files
aawsomesimonsan
andauthored
feat(commands): backup: Add option --long (#1159)
closes #1156 Co-authored-by: simonsan <[email protected]>
1 parent b865901 commit 959c057

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/commands/backup.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
use std::path::PathBuf;
44

55
use crate::{
6-
commands::{get_repository, init::init, open_repository},
7-
helpers::bytes_size_to_string,
6+
commands::{get_repository, init::init, open_repository, snapshots::fill_table},
7+
helpers::{bold_cell, bytes_size_to_string, table},
88
status_err, Application, RUSTIC_APP,
99
};
1010

1111
use abscissa_core::{Command, Runnable, Shutdown};
1212
use anyhow::{bail, Context, Result};
1313
use clap::ValueHint;
14+
use comfy_table::Cell;
1415
use log::{debug, info, warn};
1516
use merge::Merge;
1617
use serde::{Deserialize, Serialize};
@@ -63,9 +64,14 @@ pub struct BackupCmd {
6364
#[merge(strategy = merge::bool::overwrite_false)]
6465
json: bool,
6566

66-
/// Don't show any output
67+
/// Show detailed information about generated snapshot
6768
#[clap(long, conflicts_with = "json")]
6869
#[merge(strategy = merge::bool::overwrite_false)]
70+
long: bool,
71+
72+
/// Don't show any output
73+
#[clap(long, conflicts_with_all = ["json", "long"])]
74+
#[merge(strategy = merge::bool::overwrite_false)]
6975
quiet: bool,
7076

7177
/// Initialize repository, if it doesn't exist yet
@@ -238,6 +244,15 @@ impl BackupCmd {
238244
if opts.json {
239245
let mut stdout = std::io::stdout();
240246
serde_json::to_writer_pretty(&mut stdout, &snap)?;
247+
} else if opts.long {
248+
let mut table = table();
249+
250+
let add_entry = |title: &str, value: String| {
251+
_ = table.add_row([bold_cell(title), Cell::new(value)]);
252+
};
253+
fill_table(&snap, add_entry);
254+
255+
println!("{table}");
241256
} else if !opts.quiet {
242257
let summary = snap.summary.unwrap();
243258
println!(

src/commands/snapshots.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ pub fn snap_to_table(sn: &SnapshotFile, count: usize) -> [String; 9] {
164164
pub fn fill_table(snap: &SnapshotFile, mut add_entry: impl FnMut(&str, String)) {
165165
add_entry("Snapshot", snap.id.to_hex().to_string());
166166
// note that if original was not set, it is set to snap.id by the load process
167-
if snap.original != Some(snap.id) {
168-
add_entry("Original ID", snap.original.unwrap().to_hex().to_string());
167+
if let Some(original) = snap.original {
168+
if original != snap.id {
169+
add_entry("Original ID", original.to_hex().to_string());
170+
}
169171
}
170172
add_entry("Time", snap.time.format("%Y-%m-%d %H:%M:%S").to_string());
171173
add_entry("Generated by", snap.program_version.clone());

tests/show-config-fixtures/empty.txt

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ with-atime = false
3030
ignore-devid = false
3131
no-scan = false
3232
json = false
33+
long = false
3334
quiet = false
3435
init = false
3536
skip-identical-parent = false

0 commit comments

Comments
 (0)