1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 11:22:30 +01:00

Reorganise build script into modules

This commit is contained in:
cyqsimon
2023-10-30 17:49:50 +08:00
committed by Martin Nordholts
parent f3a5e9a73c
commit 79a03b4299
4 changed files with 35 additions and 31 deletions

21
build/util.rs Normal file
View File

@@ -0,0 +1,21 @@
#![allow(dead_code)]
use std::{collections::HashMap, fs, path::Path};
/// Generates a file from a template.
pub fn render_template(
variables: &HashMap<&str, String>,
in_file: &str,
out_file: impl AsRef<Path>,
) -> anyhow::Result<()> {
let mut content = fs::read_to_string(in_file)?;
for (variable_name, value) in variables {
// Replace {{variable_name}} by the value
let pattern = format!("{{{{{variable_name}}}}}");
content = content.replace(&pattern, value);
}
fs::write(out_file, content)?;
Ok(())
}