summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-12 23:51:09 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-13 20:07:55 +0200
commit35e0cd907a89b751637f71ce910950a8a8865fe0 (patch)
treea420dd3d69865e845e149d89890fe786ee71fc3e
parent97e243cd0ab5cdfeda42e373197541831bb047be (diff)
downloadrebel-35e0cd907a89b751637f71ce910950a8a8865fe0.tar
rebel-35e0cd907a89b751637f71ce910950a8a8865fe0.zip
driver: template: rename eval() to eval_sh(), eval_raw() to eval()
Make eval() the simple version that doesn't perform any escaping.
-rw-r--r--crates/driver/src/driver.rs10
-rw-r--r--crates/driver/src/template.rs24
2 files changed, 15 insertions, 19 deletions
diff --git a/crates/driver/src/driver.rs b/crates/driver/src/driver.rs
index 5a00882..28c8578 100644
--- a/crates/driver/src/driver.rs
+++ b/crates/driver/src/driver.rs
@@ -53,11 +53,9 @@ impl<'ctx> CompletionState<'ctx> {
.iter()
.map(|Fetch { name, sha256 }| {
Ok(Dependency::Fetch {
- name: template::ENGINE
- .eval_raw(name, &task.args)
- .with_context(|| {
- format!("Failed to evaluate fetch filename for task {}", task)
- })?,
+ name: template::ENGINE.eval(name, &task.args).with_context(|| {
+ format!("Failed to evaluate fetch filename for task {}", task)
+ })?,
target_dir: paths::TASK_DLDIR.to_string(),
sha256: *sha256,
})
@@ -322,7 +320,7 @@ impl<'ctx> Driver<'ctx> {
run.push(&task_def.action.run);
let command = template::ENGINE
- .eval(&run.concat(), &task_ref.args)
+ .eval_sh(&run.concat(), &task_ref.args)
.with_context(|| {
format!("Failed to evaluate command template for task {}", task_ref)
})?;
diff --git a/crates/driver/src/template.rs b/crates/driver/src/template.rs
index 7bb089c..1a091ed 100644
--- a/crates/driver/src/template.rs
+++ b/crates/driver/src/template.rs
@@ -5,38 +5,36 @@ use common::error::*;
use crate::args::TaskArgs;
-fn escape(s: &str) -> String {
+fn escape_sh(s: &str) -> String {
format!("'{}'", s.replace('\'', "'\\''"))
}
#[derive(Debug)]
pub struct TemplateEngine {
tpl: Handlebars<'static>,
- tpl_raw: Handlebars<'static>,
+ tpl_sh: Handlebars<'static>,
}
impl TemplateEngine {
pub fn new() -> Self {
let mut tpl = Handlebars::new();
tpl.set_strict_mode(true);
- tpl.register_escape_fn(escape);
+ tpl.register_escape_fn(handlebars::no_escape);
- let mut tpl_raw = Handlebars::new();
- tpl_raw.set_strict_mode(true);
- tpl_raw.register_escape_fn(handlebars::no_escape);
+ let mut tpl_sh = Handlebars::new();
+ tpl_sh.set_strict_mode(true);
+ tpl_sh.register_escape_fn(escape_sh);
- TemplateEngine { tpl, tpl_raw }
- }
-
- pub fn eval_raw(&self, input: &str, args: &TaskArgs) -> Result<String> {
- self.tpl_raw
- .render_template(input, args)
- .map_err(Error::new)
+ TemplateEngine { tpl, tpl_sh }
}
pub fn eval(&self, input: &str, args: &TaskArgs) -> Result<String> {
self.tpl.render_template(input, args).map_err(Error::new)
}
+
+ pub fn eval_sh(&self, input: &str, args: &TaskArgs) -> Result<String> {
+ self.tpl_sh.render_template(input, args).map_err(Error::new)
+ }
}
lazy_static! {