Skip to content

Commit

Permalink
fix(config)!: multiple sources in config profile as array
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Apr 18, 2024
1 parent b6e9c1b commit 1ee8838
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ use anyhow::{bail, Context, Result};
use log::{debug, info, warn};
use merge::Merge;
use serde::{Deserialize, Serialize};
use serde_with::{formats::PreferOne, serde_as, OneOrMany};

use rustic_core::{
BackupOptions, ConfigOptions, KeyOptions, LocalSourceFilterOptions, LocalSourceSaveOptions,
ParentOptions, PathList, SnapshotOptions,
};

/// `backup` subcommand
#[serde_as]
#[derive(Clone, Command, Default, Debug, clap::Parser, Serialize, Deserialize, Merge)]
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
// Note: using cli_sources, sources and source within this struct is a hack to support serde(deny_unknown_fields)
Expand Down Expand Up @@ -105,7 +107,8 @@ pub struct BackupCmd {
/// Backup source, used within config file
#[clap(skip)]
#[merge(skip)]
source: String,
#[serde_as(deserialize_as = "OneOrMany<_, PreferOne>")]
source: Vec<String>,
}

/// Merge backup sources
Expand Down Expand Up @@ -163,10 +166,13 @@ impl BackupCmd {
let config_sources: Vec<_> = config_opts
.iter()
.map(|opt| -> Result<_> {
Ok(PathList::from_string(&opt.source)?
Ok(PathList::from_iter(&opt.source)
.sanitize()
.with_context(|| {
format!("error sanitizing source=\"{}\" in config file", opt.source)
format!(
"error sanitizing source=\"{:?}\" in config file",
opt.source
)
})?
.merge())
})
Expand Down Expand Up @@ -208,7 +214,7 @@ impl BackupCmd {
}
// merge Options from config file using as_path, if given
if let Some(path) = path.as_os_str().to_str() {
if let Some(idx) = config_opts.iter().position(|opt| opt.source == path) {
if let Some(idx) = config_opts.iter().position(|opt| opt.source == vec![path]) {
info!("merging source=\"{path}\" section from config file");
opts.merge(config_opts[idx].clone());
}
Expand Down

0 comments on commit 1ee8838

Please sign in to comment.