Merge pull request #208 from rustic-rs/snapshots-json

snapshots: Add --json option
This commit is contained in:
aawsome 2022-09-15 12:11:16 +02:00 committed by GitHub
commit f9bb24ea66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 5 deletions

View File

@ -241,8 +241,8 @@ pub async fn execute() -> Result<()> {
.then(|| Cache::new(config.id, opts.cache_dir).ok())
.flatten();
match &cache {
None => v1!("using no cache"),
Some(cache) => v1!("using cache at {}", cache.location()),
None => ve1!("using no cache"),
Some(cache) => ve1!("using cache at {}", cache.location()),
}
let be_cached = CachedBackend::new(be.clone(), cache.clone());
let dbe = DecryptBackend::new(&be_cached, key.clone());

View File

@ -30,8 +30,12 @@ pub(super) struct Opts {
#[clap(long)]
long: bool,
/// Show snapshots in json format
#[clap(long, conflicts_with = "long")]
json: bool,
/// Show all snapshots instead of summarizing identical follow-up snapshots
#[clap(long)]
#[clap(long, conflicts_with_all = &["long", "json"])]
all: bool,
/// Snapshots to show
@ -67,6 +71,12 @@ pub(super) async fn execute(
)],
};
if opts.json {
let mut stdout = std::io::stdout();
serde_json::to_writer_pretty(&mut stdout, &groups)?;
return Ok(());
}
for (group, mut snapshots) in groups {
if !group.is_empty() {
println!("\nsnapshots for {:?}", group);

View File

@ -90,7 +90,7 @@ pub struct SnapshotFile {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub summary: Option<SnapshotSummary>,
#[serde(skip)]
#[serde(default, skip_serializing_if = "Id::is_null")]
pub id: Id,
}
@ -356,10 +356,13 @@ impl FromStr for SnapshotGroupCriterion {
}
}
#[derive(Default, Debug)]
#[derive(Default, Debug, Serialize)]
pub struct SnapshotGroup {
#[serde(default, skip_serializing_if = "Option::is_none")]
hostname: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
paths: Option<StringList>,
#[serde(default, skip_serializing_if = "Option::is_none")]
tags: Option<StringList>,
}