From 0503e6754c53dc6fd46a72bb56e705541ce94961 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Mon, 19 Jun 2023 06:44:11 +0200 Subject: [PATCH] Add check example --- crates/rustic_core/examples/check.rs | 14 ++++++++++++++ crates/rustic_core/src/commands/check.rs | 6 +++--- crates/rustic_core/src/repository.rs | 16 ++++++++-------- 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 crates/rustic_core/examples/check.rs diff --git a/crates/rustic_core/examples/check.rs b/crates/rustic_core/examples/check.rs new file mode 100644 index 000000000..cb56e8cbd --- /dev/null +++ b/crates/rustic_core/examples/check.rs @@ -0,0 +1,14 @@ +//! `check` example +use rustic_core::{CheckOpts, NoProgressBars, Repository, RepositoryOptions}; + +fn main() { + let opts = CheckOpts::default(); + let progress = NoProgressBars {}; + + let mut repo_opts = RepositoryOptions::default(); + repo_opts.repository = Some("/tmp/repo".to_string()); + repo_opts.password = Some("test".to_string()); + let repo = Repository::new(&repo_opts).unwrap().open().unwrap(); + + repo.check(opts, &progress).unwrap() +} diff --git a/crates/rustic_core/src/commands/check.rs b/crates/rustic_core/src/commands/check.rs index 1f9d6b73d..0832bbd8e 100644 --- a/crates/rustic_core/src/commands/check.rs +++ b/crates/rustic_core/src/commands/check.rs @@ -16,15 +16,15 @@ use crate::{ /// `check` subcommand #[cfg_attr(feature = "clap", derive(clap::Parser))] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Default)] pub struct CheckOpts { /// Don't verify the data saved in the cache #[cfg_attr(feature = "clap", clap(long, conflicts_with = "no_cache"))] - trust_cache: bool, + pub trust_cache: bool, /// Read all data blobs #[cfg_attr(feature = "clap", clap(long))] - read_data: bool, + pub read_data: bool, } impl CheckOpts { diff --git a/crates/rustic_core/src/repository.rs b/crates/rustic_core/src/repository.rs index 11d44ffde..d5f3380da 100644 --- a/crates/rustic_core/src/repository.rs +++ b/crates/rustic_core/src/repository.rs @@ -79,19 +79,19 @@ pub struct RepositoryOptions { feature = "clap", clap(short, long, global = true, alias = "repo", env = "RUSTIC_REPOSITORY") )] - repository: Option, + pub repository: Option, /// Repository to use as hot storage #[cfg_attr( feature = "clap", clap(long, global = true, alias = "repository_hot", env = "RUSTIC_REPO_HOT") )] - repo_hot: Option, + pub repo_hot: Option, /// Password of the repository - WARNING: Using --password can reveal the password in the process list! #[cfg_attr(feature = "clap", clap(long, global = true, env = "RUSTIC_PASSWORD"))] // TODO: use `secrecy` library - password: Option, + pub password: Option, /// File to read the password from #[cfg_attr( @@ -104,7 +104,7 @@ pub struct RepositoryOptions { conflicts_with = "password" ) )] - password_file: Option, + pub password_file: Option, /// Command to read the password from #[cfg_attr(feature = "clap", clap( @@ -113,12 +113,12 @@ pub struct RepositoryOptions { env = "RUSTIC_PASSWORD_COMMAND", conflicts_with_all = &["password", "password_file"], ))] - password_command: Option, + pub password_command: Option, /// Don't use a cache. #[cfg_attr(feature = "clap", clap(long, global = true, env = "RUSTIC_NO_CACHE"))] #[cfg_attr(feature = "merge", merge(strategy = merge::bool::overwrite_false))] - no_cache: bool, + pub no_cache: bool, /// Use this dir as cache dir instead of the standard cache dir #[cfg_attr( @@ -130,7 +130,7 @@ pub struct RepositoryOptions { env = "RUSTIC_CACHE_DIR" ) )] - cache_dir: Option, + pub cache_dir: Option, /// Warm up needed data pack files by only requesting them without processing #[cfg_attr(feature = "clap", clap(long, global = true))] @@ -151,7 +151,7 @@ pub struct RepositoryOptions { #[cfg_attr(feature = "clap", clap(skip))] #[cfg_attr(feature = "merge", merge(strategy = overwrite))] - options: HashMap, + pub options: HashMap, } // TODO: Unused function