Skip to content

Commit bdfd2bd

Browse files
committed
Tracing logs and use render_strict helper
Signed-off-by: Robert Detjens <[email protected]>
1 parent 4b3723c commit bdfd2bd

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/commands/init.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use anyhow::{Context, Result};
22
use std::fs::File;
33
use std::io::Write;
44
use std::process::exit;
@@ -7,18 +7,16 @@ use tracing::error;
77
use crate::init::{self as init, templatize_init};
88
use crate::{access_handlers::frontend, commands::deploy};
99

10-
pub fn run(_interactive: &bool, _blank: &bool) -> Result<()> {
11-
let options: init::InitVars;
12-
13-
if *_interactive {
14-
options = init::interactive_init()?;
15-
} else if *_blank {
16-
options = init::blank_init();
10+
pub fn run(interactive: &bool, blank: &bool) -> Result<()> {
11+
let options = if *interactive {
12+
init::interactive_init()?
13+
} else if *blank {
14+
init::blank_init()
1715
} else {
18-
options = init::example_init();
19-
}
16+
init::example_init()
17+
};
2018

21-
let configuration = templatize_init(options);
19+
let configuration = templatize_init(options).context("could not render template")?;
2220

2321
let mut f = File::create("rcds.yaml")?;
2422
f.write_all(configuration.as_bytes())?;

src/init/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
use anyhow::Result;
12
use inquire;
23
use minijinja;
34
use regex::Regex;
45
use serde;
56
use std::fmt;
7+
use tracing::{debug, error, info, trace, warn};
8+
9+
use crate::utils::render_strict;
610

711
pub mod example_values;
812
pub mod templates;
913

10-
#[derive(serde::Serialize, Default)]
14+
#[derive(serde::Serialize, Default, Debug)]
1115
pub struct InitVars {
1216
pub flag_regex: String,
1317
pub registry_domain: String,
@@ -22,7 +26,7 @@ pub struct InitVars {
2226
pub profiles: Vec<Profile>,
2327
}
2428

25-
#[derive(Clone, serde::Serialize, Default)]
29+
#[derive(Clone, serde::Serialize, Default, Debug)]
2630
pub struct Points {
2731
pub difficulty: String,
2832
pub min: String,
@@ -39,7 +43,7 @@ impl fmt::Display for Points {
3943
}
4044
}
4145

42-
#[derive(serde::Serialize, Default)]
46+
#[derive(serde::Serialize, Default, Debug)]
4347
pub struct Profile {
4448
pub profile_name: String,
4549
pub frontend_url: String,
@@ -274,10 +278,12 @@ pub fn interactive_init() -> inquire::error::InquireResult<InitVars> {
274278
}
275279

276280
pub fn blank_init() -> InitVars {
281+
trace!("building blank config");
277282
InitVars::default()
278283
}
279284

280285
pub fn example_init() -> InitVars {
286+
trace!("building example values config");
281287
InitVars {
282288
flag_regex: String::from(example_values::FLAG_REGEX),
283289
registry_domain: String::from(example_values::REGISTRY_DOMAIN),
@@ -315,6 +321,7 @@ pub fn example_init() -> InitVars {
315321
}
316322
}
317323

318-
pub fn templatize_init(options: InitVars) -> String {
319-
minijinja::render!(templates::RCDS, options)
324+
pub fn templatize_init(options: InitVars) -> Result<String> {
325+
debug!("rendering template with {options:?}");
326+
render_strict(templates::RCDS, minijinja::context! {options})
320327
}

0 commit comments

Comments
 (0)