1use crate::{Spec, SpecCommand};
2use once_cell::sync::Lazy;
3use tera::Tera;
4
5pub fn render_help(spec: &Spec, cmd: &SpecCommand, long: bool) -> String {
6 let mut ctx = tera::Context::new();
7 ctx.insert("spec", spec);
8 ctx.insert("cmd", cmd);
9 ctx.insert("long", &long);
10 let template = if long {
11 "spec_template_long.tera"
12 } else {
13 "spec_template_short.tera"
14 };
15 TERA.render(template, &ctx).unwrap().trim().to_string() + "\n"
16}
17
18static TERA: Lazy<Tera> = Lazy::new(|| {
19 let mut tera = Tera::default();
20
21 #[rustfmt::skip]
22 tera.add_raw_templates([
23 ("spec_template_short.tera", include_str!("templates/spec_template_short.tera")),
24 ("spec_template_long.tera", include_str!("templates/spec_template_long.tera")),
25 ]).unwrap();
26
27 tera
37});