usage/docs/cli/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::{Spec, SpecCommand};
use once_cell::sync::Lazy;
use tera::Tera;

pub fn render_help(spec: &Spec, cmd: &SpecCommand, long: bool) -> String {
    let mut ctx = tera::Context::new();
    ctx.insert("spec", spec);
    ctx.insert("cmd", cmd);
    ctx.insert("long", &long);
    let template = if long {
        "spec_template_long.tera"
    } else {
        "spec_template_short.tera"
    };
    TERA.render(template, &ctx).unwrap().trim().to_string() + "\n"
}

static TERA: Lazy<Tera> = Lazy::new(|| {
    let mut tera = Tera::default();

    #[rustfmt::skip]
    tera.add_raw_templates([
        ("spec_template_short.tera", include_str!("templates/spec_template_short.tera")),
        ("spec_template_long.tera", include_str!("templates/spec_template_long.tera")),
    ]).unwrap();

    // tera.register_filter(
    //     "repeat",
    //     move |value: &tera::Value, args: &HashMap<String, tera::Value>| {
    //         let value = value.as_str().unwrap();
    //         let count = args.get("count").unwrap().as_u64().unwrap();
    //         Ok(value.repeat(count as usize).into())
    //     },
    // );

    tera
});