diff --git a/src/config.rs b/src/config.rs index afdd9f4..652cd47 100644 --- a/src/config.rs +++ b/src/config.rs @@ -85,10 +85,25 @@ pub enum DefaultTargetType { Automatic, } -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Settings { #[serde(default)] default_target_type: DefaultTargetType, + #[serde(default = "default_true")] + recurse: bool, +} + +impl Default for Settings { + fn default() -> Self { + Settings { + default_target_type: DefaultTargetType::default(), + recurse: true, + } + } +} + +fn default_true() -> bool { + true } #[derive(Debug, Clone)] @@ -100,13 +115,6 @@ pub struct Configuration { #[cfg(feature = "scripting")] pub helpers: Helpers, - /// If the source is a directory, or a symlink to a directory, - /// and this option is true, the source will be recursed and - /// turned into a list of all the files inside the structure that - /// are readable. - pub recurse: bool, - - #[allow(dead_code)] pub settings: Settings, } @@ -348,8 +356,7 @@ fn merge_configuration_files( files: Files::default(), variables: Variables::default(), packages: packages_map, - recurse: true, - settings: Settings::default(), + settings: global.settings, }; // Merge all the packages @@ -395,7 +402,7 @@ fn merge_configuration_files( for value in output.files.values_mut() { if let FileTarget::Automatic(target) = value { - *value = match global.settings.default_target_type { + *value = match output.settings.default_target_type { DefaultTargetType::Symbolic => { FileTarget::Symbolic(SymbolicTarget::from(target.clone())) } @@ -554,16 +561,12 @@ fn expand_directory(source: &Path, target: &FileTarget, config: &Configuration) condition: _, recurse: Some(rec), }) => *rec, - _ => config.recurse, + _ => config.settings.recurse, }; trace!("expanding '{source:?}', recurse: {recurse}"); - if !recurse || !metadata.is_dir() { - let mut map = Files::new(); - map.insert(source.into(), target.clone()); - Ok(map) - } else { + if recurse && metadata.is_dir() { let expanded = fs::read_dir(source) .context("read contents of directory")? .map(|child| -> Result { @@ -576,6 +579,10 @@ fn expand_directory(source: &Path, target: &FileTarget, config: &Configuration) }) .collect::>>()?; // Use transposition of Iterator> -> Result, E> Ok(expanded.into_iter().flatten().collect()) + } else { + let mut map = Files::new(); + map.insert(source.into(), target.clone()); + Ok(map) } } @@ -817,7 +824,7 @@ mod test { assert_eq!( cat, - &FileTarget::Automatic(PathBuf::from("~/.QuarticCat").into()) + &FileTarget::Automatic(PathBuf::from("~/.QuarticCat")) ); assert_eq!( diff --git a/src/handlebars_helpers.rs b/src/handlebars_helpers.rs index beda2dd..e6a2fe7 100644 --- a/src/handlebars_helpers.rs +++ b/src/handlebars_helpers.rs @@ -363,7 +363,6 @@ mod test { #[cfg(feature = "scripting")] helpers: Helpers::new(), packages: maplit::btreemap! { "default".into() => true, "disabled".into() => false }, - recurse: true, settings: Settings::default(), }; let handlebars = create_new_handlebars(&mut config).unwrap(); @@ -390,7 +389,6 @@ mod test { #[cfg(feature = "scripting")] helpers: Helpers::new(), packages: BTreeMap::new(), - recurse: true, settings: Settings::default(), }; let handlebars = create_new_handlebars(&mut config).unwrap();