Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include disabled packages in dotter.packages #131

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub type Helpers = BTreeMap<String, PathBuf>;
pub struct Configuration {
pub files: Files,
pub variables: Variables,
pub packages: Vec<String>,
pub packages: BTreeMap<String, bool>,

#[cfg(feature = "scripting")]
pub helpers: Helpers,
Expand Down Expand Up @@ -304,6 +304,12 @@ fn merge_configuration_files(
enabled_packages.extend(new_packages);
}

let packages_map = global
.packages
.keys()
.map(|k| (k.to_string(), enabled_packages.contains(k)))
.collect();

// Apply packages filter
global.packages.retain(|k, _| enabled_packages.contains(k));

Expand All @@ -312,7 +318,7 @@ fn merge_configuration_files(
helpers: global.helpers,
files: Files::default(),
variables: Variables::default(),
packages: enabled_packages.into_iter().collect(),
packages: packages_map,
recurse: true,
};

Expand Down
23 changes: 18 additions & 5 deletions src/handlebars_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::{Context as AnyhowContext, Result};
use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError};
use toml::value::{Table, Value};

use std::collections::BTreeSet;
use std::collections::{BTreeMap, BTreeSet};
use std::path::PathBuf;
use std::process::{Command, Stdio};

Expand Down Expand Up @@ -298,14 +298,18 @@ fn files_as_toml(files: &Files) -> Value {
)
}

fn add_dotter_variable(variables: &mut Variables, files: &Files, packages: &[String]) {
fn add_dotter_variable(
variables: &mut Variables,
files: &Files,
packages: &BTreeMap<String, bool>,
) {
let mut dotter = Table::new();
dotter.insert(
"packages".into(),
Value::Table(
packages
.iter()
.map(|p| (p.to_string(), Value::Boolean(true)))
.map(|(p, e)| (p.to_string(), Value::Boolean(*e)))
.collect(),
),
);
Expand Down Expand Up @@ -345,7 +349,7 @@ mod test {
files: Files::new(),
variables: maplit::btreemap! { "foo".into() => 2.into() },
helpers: Helpers::new(),
packages: vec!["default".into()],
packages: maplit::btreemap! { "default".into() => true, "disabled".into() => false },
recurse: true,
};
let handlebars = create_new_handlebars(&mut config).unwrap();
Expand All @@ -366,6 +370,15 @@ mod test {
eval_condition(&handlebars, &config.variables, "dotter.packages.nonexist").unwrap(),
false
);
assert_eq!(
eval_condition(
&handlebars,
&config.variables,
"(and true dotter.packages.disabled)"
)
.unwrap(),
false
);
}

#[test]
Expand All @@ -374,7 +387,7 @@ mod test {
files: Files::new(),
variables: Variables::new(),
helpers: Helpers::new(),
packages: vec!["default".into()],
packages: BTreeMap::new(),
recurse: true,
};
let handlebars = create_new_handlebars(&mut config).unwrap();
Expand Down