Skip to content

Commit

Permalink
fix!: use multiple options only as array in config profile
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Sep 16, 2024
1 parent abf1835 commit 7b89fbe
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
18 changes: 9 additions & 9 deletions config/full-one.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Global options: These options are used for all commands.
[global]
use-profile = []
use-profiles = []
log-level = "info" # any of "off", "error", "warn", "info", "debug", "trace"; default: "info"
log-file = "/path/to/rustic.log" # Default: not set
no-progress = false
Expand Down Expand Up @@ -70,10 +70,10 @@ throttle = "10kB,10MB" # limit and burst per second; only opendal backends; Defa

# Snapshot-filter options: These options apply to all commands that use snapshot filters
[snapshot-filter]
filter-host = "host2" # Default: no host filter
filter-label = "label1" # Default: no label filter
filter-tags = "tag1,tag2" # Default: no tags filger
filter-paths = "path1" # Default: no paths filter
filter-host = ["host2"] # Default: []
filter-label = ["label1"] # Default: []
filter-tags = ["tag1,tag2"] # Default: []
filter-paths = ["path1"] # Default: []
filter-fn = '|sn| {sn.host == "host1" || sn.description.contains("test")}' # Default: no filter function

# Backup options: These options are used for all sources when calling the backup command.
Expand Down Expand Up @@ -122,10 +122,10 @@ label = "label" # Default: not set
prune = false
group-by = "host,label,paths" # Can be any combination of host,label,paths,tags
# The following filter options can be also defined here and then overwrite the options for the forget command
filter-host = "host2" # Default: no host filter
filter-label = "label1" # Default: no label filter
filter-tags = "tag1,tag2" # Default: no tags filger
filter-paths = "path1" # Default: no paths filter
filter-host = ["host2"] # Default: []
filter-label = ["label1"] # Default: []
filter-tags = ["tag1,tag2"] # Default: []
filter-paths = ["path1"] # Default: no paths filter
filter-fn = '|sn| {sn.host == "host1" || sn.description.contains("test")}' # Default: no filter function
# The retention options follow. All of these are not set by default.
keep-tags = "tag1" # Default: not set
Expand Down
18 changes: 9 additions & 9 deletions config/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Global options: These options are used for all commands.
[global]
use-profile = []
use-profiles = []
log-level = "info" # any of "off", "error", "warn", "info", "debug", "trace"; default: "info"
log-file = "/path/to/rustic.log" # Default: not set
no-progress = false
Expand Down Expand Up @@ -67,10 +67,10 @@ throttle = "10kB,10MB" # limit and burst per second; only opendal backends; Defa

# Snapshot-filter options: These options apply to all commands that use snapshot filters
[snapshot-filter]
filter-host = ["host2", "host2"] # Default: no host filter
filter-label = ["label1", "label2"] # Default: no label filter
filter-tags = ["tag1,tag2", "tag3"] # Default: no tags filger
filter-paths = ["path1", "path2,path3"] # Default: no paths filter
filter-host = ["host2", "host2"] # Default: []
filter-label = ["label1", "label2"] # Default: []
filter-tags = ["tag1,tag2", "tag3"] # Default: []
filter-paths = ["path1", "path2,path3"] # Default: []
filter-fn = '|sn| {sn.host == "host1" || sn.description.contains("test")}' # Default: no filter function

# Backup options: These options are used for all sources when calling the backup command.
Expand Down Expand Up @@ -126,10 +126,10 @@ source = [
prune = false
group-by = "host,label,paths" # Can be any combination of host,label,paths,tags
# The following filter options can be also defined here and then overwrite the options for the forget command
filter-host = ["host2", "host2"] # Default: no host filter
filter-label = ["label1", "label2"] # Default: no label filter
filter-tags = ["tag1,tag2", "tag3"] # Default: no tags filger
filter-paths = ["path1", "path2,path3"] # Default: no paths filter
filter-host = ["host2", "host2"] # Default: []
filter-label = ["label1", "label2"] # Default: []
filter-tags = ["tag1,tag2", "tag3"] # Default: []
filter-paths = ["path1", "path2,path3"] # Default: []
filter-fn = '|sn| {sn.host == "host1" || sn.description.contains("test")}' # Default: no filter function
# The retention options follow. All of these are not set by default.
keep-tags = ["tag1", "tag2,tag3"] # Default: not set
Expand Down
4 changes: 2 additions & 2 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ impl Configurable<RusticConfig> for EntryPoint {
let mut merge_logs = Vec::new();

// get global options from command line / env and config file
if config.global.use_profile.is_empty() {
if config.global.use_profiles.is_empty() {
config.merge_profile("rustic", &mut merge_logs, Level::Info)?;
} else {
for profile in &config.global.use_profile.clone() {
for profile in &config.global.use_profiles.clone() {
config.merge_profile(profile, &mut merge_logs, Level::Warn)?;
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use merge::Merge;
use rustic_backend::BackendOptions;
use rustic_core::RepositoryOptions;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, OneOrMany};

#[cfg(feature = "webdav")]
use crate::commands::webdav::WebDavCmd;
Expand Down Expand Up @@ -104,7 +103,7 @@ impl RusticConfig {
merge_logs.push((Level::Info, format!("using config {}", path.display())));
let mut config = Self::load_toml_file(AbsPathBuf::canonicalize(path)?)?;
// if "use_profile" is defined in config file, merge the referenced profiles first
for profile in &config.global.use_profile.clone() {
for profile in &config.global.use_profiles.clone() {
config.merge_profile(profile, merge_logs, Level::Warn)?;
}
self.merge(config);
Expand All @@ -125,22 +124,20 @@ impl RusticConfig {
/// Global options
///
/// These options are available for all commands.
#[serde_as]
#[derive(Default, Debug, Parser, Clone, Deserialize, Serialize, Merge)]
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
pub struct GlobalOptions {
/// Config profile to use. This parses the file `<PROFILE>.toml` in the config directory.
/// [default: "rustic"]
#[clap(
short = 'P',
long,
long = "use-profile",
global = true,
value_name = "PROFILE",
env = "RUSTIC_USE_PROFILE"
)]
#[merge(strategy = merge::vec::append)]
#[serde_as(as = "OneOrMany<_>")]
pub use_profile: Vec<String>,
pub use_profiles: Vec<String>,

/// Only show what would be done without modifying anything. Does not affect read-only commands.
#[clap(long, short = 'n', global = true, env = "RUSTIC_DRY_RUN")]
Expand Down
8 changes: 3 additions & 5 deletions src/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{error::Error, str::FromStr};
use cached::proc_macro::cached;
use rhai::{serde::to_dynamic, Dynamic, Engine, FnPtr, AST};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr, OneOrMany};
use serde_with::{serde_as, DisplayFromStr};

/// A function to filter snapshots
///
Expand Down Expand Up @@ -61,24 +61,22 @@ pub struct SnapshotFilter {
/// Hostname to filter (can be specified multiple times)
#[clap(long, global = true, value_name = "HOSTNAME")]
#[merge(strategy=merge::vec::overwrite_empty)]
#[serde_as(as = "OneOrMany<_>")]
filter_host: Vec<String>,

/// Label to filter (can be specified multiple times)
#[clap(long, global = true, value_name = "LABEL")]
#[merge(strategy=merge::vec::overwrite_empty)]
#[serde_as(as = "OneOrMany<_>")]
filter_label: Vec<String>,

/// Path list to filter (can be specified multiple times)
#[clap(long, global = true, value_name = "PATH[,PATH,..]")]
#[serde_as(as = "OneOrMany<DisplayFromStr>")]
#[serde_as(as = "Vec<DisplayFromStr>")]
#[merge(strategy=merge::vec::overwrite_empty)]
filter_paths: Vec<StringList>,

/// Tag list to filter (can be specified multiple times)
#[clap(long, global = true, value_name = "TAG[,TAG,..]")]
#[serde_as(as = "OneOrMany<DisplayFromStr>")]
#[serde_as(as = "Vec<DisplayFromStr>")]
#[merge(strategy=merge::vec::overwrite_empty)]
filter_tags: Vec<StringList>,

Expand Down

0 comments on commit 7b89fbe

Please sign in to comment.