diff --git a/changelog/new.txt b/changelog/new.txt index 2291809..2f2696c 100644 --- a/changelog/new.txt +++ b/changelog/new.txt @@ -1,6 +1,7 @@ Changes in version x.x.x: Breaking changes: +- config file: use-config now expects an array of config profiles to read. Bugs fixed: - The [[backup.sources]] section in the config file was ignored 0.5.2. This has been fixed. diff --git a/examples/full.toml b/examples/full.toml index 0b62397..699763a 100644 --- a/examples/full.toml +++ b/examples/full.toml @@ -7,7 +7,7 @@ # Global options: These options are used for all commands. [global] -use-profile = "" +use-profile = [] 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 diff --git a/src/commands/configfile.rs b/src/commands/configfile.rs index 1bb11a8..f0d892f 100644 --- a/src/commands/configfile.rs +++ b/src/commands/configfile.rs @@ -51,9 +51,8 @@ impl Config { let mut config: Self = toml::from_str(&data).context("error reading TOML from config file")?; // if "use_profile" is defined in config file, merge this referenced profile first - if !config.global.use_profile.is_empty() { - let profile = config.global.use_profile.clone(); - config.merge_profile(&profile)?; + for profile in &config.global.use_profile.clone() { + config.merge_profile(profile)?; } self.merge(config); } else { diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 2ecbce6..8c85d72 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -54,16 +54,16 @@ struct Args { #[serde(default, rename_all = "kebab-case", deny_unknown_fields)] pub struct GlobalOpts { /// Config profile to use. This parses the file `.toml` in the config directory. + /// [default: "rustic"] #[clap( short = 'P', long, global = true, value_name = "PROFILE", - default_value = "rustic", env = "RUSTIC_USE_PROFILE" )] - #[merge(skip)] - use_profile: String, + #[merge(strategy = merge::vec::append)] + use_profile: Vec, /// 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")] @@ -168,10 +168,15 @@ pub fn execute() -> Result<()> { let command: Vec<_> = std::env::args_os().collect(); let args = Args::parse_from(&command); let mut config = args.config; + if config.global.use_profile.is_empty() { + config.global.use_profile.push("rustic".to_string()); + } // get global options from command line / env and config file - let profile = config.global.use_profile.clone(); - config.merge_profile(&profile)?; + for profile in &config.global.use_profile.clone() { + config.merge_profile(profile)?; + } + // start logger let level_filter = config.global.log_level.unwrap_or(LevelFilter::Info);