diff options
author | 2021-07-29 16:24:27 +0200 | |
---|---|---|
committer | 2021-08-25 08:11:28 -0700 | |
commit | fe6608425e6217097aab82b89d4a72b79d94c8da (patch) | |
tree | 555e1f87a1ddcd7a4ee9e987571e1cdf9bd51d64 | |
parent | Update the lockfile (diff) | |
download | cargo-ebuild-fe6608425e6217097aab82b89d4a72b79d94c8da.tar.gz cargo-ebuild-fe6608425e6217097aab82b89d4a72b79d94c8da.tar.bz2 cargo-ebuild-fe6608425e6217097aab82b89d4a72b79d94c8da.zip |
Add an option to provide a custom tera template
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>
-rw-r--r-- | src/lib.rs | 12 | ||||
-rw-r--r-- | src/main.rs | 5 |
2 files changed, 14 insertions, 3 deletions
@@ -123,7 +123,11 @@ pub fn gen_ebuild_data(manifest_path: Option<PathBuf>) -> Result<EbuildConfig> { Ok(EbuildConfig::from_package(root_pkg, crates, licenses)) } -pub fn write_ebuild(ebuild_data: EbuildConfig, ebuild_path: impl AsRef<Path>) -> Result<()> { +pub fn write_ebuild( + ebuild_data: EbuildConfig, + ebuild_path: impl AsRef<Path>, + template_path: Option<impl AsRef<Path>>, +) -> Result<()> { // Open the file where we'll write the ebuild let mut file = OpenOptions::new() .write(true) @@ -137,7 +141,11 @@ pub fn write_ebuild(ebuild_data: EbuildConfig, ebuild_path: impl AsRef<Path>) -> let mut tera = tera::Tera::default(); let mut context = tera::Context::from_serialize(ebuild_data)?; - tera.add_raw_template("ebuild.tera", include_str!("ebuild.tera"))?; + if let Some(template) = template_path { + tera.add_template_file(template, Some("ebuild.tera"))?; + } else { + tera.add_raw_template("ebuild.tera", include_str!("ebuild.tera"))?; + } context.insert("cargo_ebuild_ver", env!("CARGO_PKG_VERSION")); context.insert("this_year", &time::OffsetDateTime::now_utc().year()); diff --git a/src/main.rs b/src/main.rs index 94aa1af..fe8881c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,9 @@ struct Args { #[structopt(name = "PATH", long = "manifest-path", parse(from_os_str))] /// Path to Cargo.toml. manifest_path: Option<PathBuf>, + #[structopt(name = "TEMPLATE", long = "template-path", short)] + /// Non-standard template + template_path: Option<PathBuf>, } #[derive(StructOpt, Debug)] @@ -46,7 +49,7 @@ fn main() -> Result<()> { let ebuild_path = format!("{}-{}.ebuild", ebuild_data.name, ebuild_data.version); - write_ebuild(ebuild_data, &ebuild_path)?; + write_ebuild(ebuild_data, &ebuild_path, opt.template_path.as_ref())?; println!("Wrote: {}", ebuild_path); |