Skip to content

Commit

Permalink
feat: add OS template var
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Nov 2, 2023
1 parent a5fa4f5 commit bc8d283
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl Bombadil {
let profiles_values = serde_json::to_value(&self.profile_enabled)?;
let mut profiles_context = tera::Map::new();
profiles_context.insert("profiles".to_string(), profiles_values);

self.vars.extend(Variables {
inner: Value::Object(profiles_context),
});
Expand Down Expand Up @@ -519,7 +520,8 @@ impl Bombadil {
};

// Resolve variables from path
let vars = Variables::from_paths(&path, &config.settings.vars)?;
let vars = Variables::from_paths(&path, &config.settings.vars)?
.with_os();

// Resolve hooks from settings
let posthooks = config
Expand Down
9 changes: 9 additions & 0 deletions src/templating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ impl Variables {
.get_mut("secrets")
.and_then(|value| value.as_object_mut())
}

pub(crate) fn with_os(mut self) -> Self {
let Some(vars) = self.inner.as_object_mut() else {
panic!("Variables should be a Value::Object");
};

vars.insert("os".to_string(), Value::String(std::env::consts::OS.to_string()));
self
}
}

#[cfg(test)]
Expand Down

0 comments on commit bc8d283

Please sign in to comment.