rustic_rs/commands/
check.rs1use crate::{
4 Application, RUSTIC_APP,
5 repository::{OpenRepo, get_global_grouped_snapshots},
6 status_err,
7};
8
9use abscissa_core::{Command, Runnable, Shutdown};
10use anyhow::Result;
11use rustic_core::{CheckOptions, repofile::SnapshotFile};
12
13#[derive(clap::Parser, Command, Debug)]
15pub(crate) struct CheckCmd {
16 #[clap(value_name = "ID")]
20 ids: Vec<String>,
21
22 #[clap(flatten)]
24 opts: CheckOptions,
25}
26
27impl Runnable for CheckCmd {
28 fn run(&self) {
29 if let Err(err) = RUSTIC_APP
30 .config()
31 .repository
32 .run_open(|repo| self.inner_run(repo))
33 {
34 status_err!("{}", err);
35 RUSTIC_APP.shutdown(Shutdown::Crash);
36 };
37 }
38}
39
40impl CheckCmd {
41 fn inner_run(&self, repo: OpenRepo) -> Result<()> {
42 let snaps: Vec<SnapshotFile> = get_global_grouped_snapshots(&repo, &self.ids)?.into();
43 let trees = snaps.into_iter().map(|snap| snap.tree).collect();
44 repo.check_with_trees(self.opts, trees)?.is_ok()?;
45 Ok(())
46 }
47}