mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
Merge pull request #208 from rustic-rs/snapshots-json
snapshots: Add --json option
This commit is contained in:
commit
f9bb24ea66
@ -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());
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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>,
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user