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