Skip to content

Commit

Permalink
feat(commands): backup: Add option --long
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed May 28, 2024
1 parent fc8e3c5 commit 5cb2134
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!(
Expand Down
6 changes: 4 additions & 2 deletions src/commands/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 5cb2134

Please sign in to comment.