Skip to content

Commit

Permalink
feat: sat templates now accepts lines starting with '#' as comments
Browse files Browse the repository at this point in the history
feat: sat template rendering fails if values are missing
feat: sat template rendering ebug enabled for better errors
  • Loading branch information
Manuel Sopena Ballesteros committed Nov 4, 2024
1 parent e693d7f commit 913235f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ humansize = "2.0.0"
indicatif = "0.17.7"
execute = "0.2.13"
is_executable = "1.0.1"
minijinja = "1.0.12"
minijinja = { version = "2.4.0", features = ["custom_syntax"] }
uuid = { version = "1.10.0", features = ["v4", "fast-rng"] }

[build-dependencies]
Expand Down
21 changes: 14 additions & 7 deletions src/cli/commands/apply_sat_file/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use mesa::{
error::Error,
hsm, ims,
};
use minijinja::Environment;
use serde::{Deserialize, Serialize};
use serde_json::Map;
use serde_yaml::{Mapping, Value};
Expand Down Expand Up @@ -558,7 +557,20 @@ pub fn render_jinja2_sat_file_yaml(
values_file_content_opt: Option<&String>,
value_cli_vec_opt: Option<Vec<String>>,
) -> Value {
let env = minijinja::Environment::new();
let mut env = minijinja::Environment::new();
// Set/enable debug in order to force minijinja to print debug error messages which are more
// descriptive. Eg https://github.com/mitsuhiko/minijinja/blob/main/examples/error/src/main.rs#L4-L5
env.set_debug(true);
// Set lines starting with `#` as comments
env.set_syntax(
minijinja::syntax::SyntaxConfig::builder()
.line_comment_prefix("#")
.build()
.unwrap(),
);
// Set 'String' as undefined behaviour meaning, missing values won't pass the template
// rendering
env.set_undefined_behavior(minijinja::UndefinedBehavior::Strict);

// Render session values file
let mut values_file_yaml: Value = if let Some(values_file_content) = values_file_content_opt {
Expand Down Expand Up @@ -592,11 +604,6 @@ pub fn render_jinja2_sat_file_yaml(
}

// render sat template file
// Set/enable debug in order to force minijinja to print debug error messages which are more
// descriptive. Eg https://github.com/mitsuhiko/minijinja/blob/main/examples/error/src/main.rs#L4-L5
let mut env = Environment::new();
env.set_debug(true);

let sat_file_rendered_rslt = env.render_str(sat_file_content, values_file_yaml);

let sat_file_rendered = match sat_file_rendered_rslt {
Expand Down

0 comments on commit 913235f

Please sign in to comment.