From 357c61f229867528f0051488361a2bd15c91915c Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Thu, 21 Jul 2022 12:51:54 +0200 Subject: [PATCH] snapshots: allow argument "latest" --- src/commands/snapshots.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/commands/snapshots.rs b/src/commands/snapshots.rs index 10bea0a..09b2192 100644 --- a/src/commands/snapshots.rs +++ b/src/commands/snapshots.rs @@ -30,9 +30,22 @@ pub(super) struct Opts { } pub(super) async fn execute(be: &impl DecryptReadBackend, opts: Opts) -> Result<()> { - let groups = match opts.ids.is_empty() { - true => SnapshotFile::group_from_backend(be, &opts.filter, &opts.group_by).await?, - false => vec![( + let groups = match &opts.ids[..] { + [] => SnapshotFile::group_from_backend(be, &opts.filter, &opts.group_by).await?, + [id] if id == "latest" => { + SnapshotFile::group_from_backend(be, &opts.filter, &opts.group_by) + .await? + .into_iter() + .map(|(group, mut snaps)| { + snaps.sort_unstable(); + let last_idx = snaps.len() - 1; + snaps.swap(0, last_idx); + snaps.truncate(1); + (group, snaps) + }) + .collect::>() + } + _ => vec![( SnapshotGroup::default(), SnapshotFile::from_ids(be, &opts.ids).await?, )],