rustic_rs/commands/
check.rs

1//! `check` subcommand
2
3use crate::{
4    Application, RUSTIC_APP,
5    repository::{CliOpenRepo, get_global_grouped_snapshots},
6    status_err,
7};
8
9use abscissa_core::{Command, Runnable, Shutdown};
10use anyhow::Result;
11use rustic_core::CheckOptions;
12
13/// `check` subcommand
14#[derive(clap::Parser, Command, Debug)]
15pub(crate) struct CheckCmd {
16    /// Snapshots to check. If none is given, use filter options to filter from all snapshots
17    #[clap(value_name = "ID")]
18    ids: Vec<String>,
19
20    /// Check options
21    #[clap(flatten)]
22    opts: CheckOptions,
23}
24
25impl Runnable for CheckCmd {
26    fn run(&self) {
27        if let Err(err) = RUSTIC_APP
28            .config()
29            .repository
30            .run_open(|repo| self.inner_run(repo))
31        {
32            status_err!("{}", err);
33            RUSTIC_APP.shutdown(Shutdown::Crash);
34        };
35    }
36}
37
38impl CheckCmd {
39    fn inner_run(&self, repo: CliOpenRepo) -> Result<()> {
40        let groups = get_global_grouped_snapshots(&repo, &self.ids)?;
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)?.is_ok()?;
47        Ok(())
48    }
49}