use chrono::prelude::*; const README_TEMPLATE: &str = include_str!("../doc/README.tera.md"); const CLI_MENU: &str = include_str!("../doc/cli-menu.txt"); const JUST_COMMANDS: &str = include_str!("../doc/just-commands.txt"); const CONFIG_SAMPLE: &str = include_str!("../config.toml.sample"); fn get_commit_ref() -> Result> { let output = std::process::Command::new("git") .args(&["rev-parse", "HEAD"][..]) .output()? .stdout; let commit = std::str::from_utf8(&output[..8]).map(|x| x.to_string())?; Ok(commit) } fn main() -> Result<(), Box> { let mut tera = tera::Tera::default(); tera.add_raw_template("README.md", README_TEMPLATE).unwrap(); let mut ctx = tera::Context::new(); ctx.insert("cli_menu", CLI_MENU); ctx.insert("config_sample", CONFIG_SAMPLE); ctx.insert("just_commands", JUST_COMMANDS); ctx.insert("git_commit", &get_commit_ref()?); ctx.insert("generation_time", &Utc::now().to_rfc2822()); let readme = tera.render("README.md", &ctx)?; println!("{}", readme); Ok(()) }