Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(commands): backup: Add option --long #1159

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
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 clap::ValueHint;
use comfy_table::Cell;
use log::{debug, info, warn};
use merge::Merge;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -63,9 +64,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 @@ -238,6 +244,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 @@ -164,8 +164,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
1 change: 1 addition & 0 deletions tests/show-config-fixtures/empty.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading