usage/docs/cli/
mod.rs

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.register_filter(
28    //     "repeat",
29    //     move |value: &tera::Value, args: &HashMap<String, tera::Value>| {
30    //         let value = value.as_str().unwrap();
31    //         let count = args.get("count").unwrap().as_u64().unwrap();
32    //         Ok(value.repeat(count as usize).into())
33    //     },
34    // );
35
36    tera
37});