From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 5D33C1580B9 for ; Wed, 25 Aug 2021 15:35:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 98AD1E08E5; Wed, 25 Aug 2021 15:35:09 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DEDCFE08E5 for ; Wed, 25 Aug 2021 15:35:08 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id ECB3133BDC5 for ; Wed, 25 Aug 2021 15:35:06 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6152B8D4 for ; Wed, 25 Aug 2021 15:35:05 +0000 (UTC) From: "Georgy Yakovlev" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Georgy Yakovlev" Message-ID: <1629904288.fe6608425e6217097aab82b89d4a72b79d94c8da.gyakovlev@gentoo> Subject: [gentoo-commits] proj/cargo-ebuild:master commit in: src/ X-VCS-Repository: proj/cargo-ebuild X-VCS-Files: src/lib.rs src/main.rs X-VCS-Directories: src/ X-VCS-Committer: gyakovlev X-VCS-Committer-Name: Georgy Yakovlev X-VCS-Revision: fe6608425e6217097aab82b89d4a72b79d94c8da X-VCS-Branch: master Date: Wed, 25 Aug 2021 15:35:05 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 2edb6573-2b02-497c-acf7-a84b57b555ed X-Archives-Hash: 737819560927ac335e2ba13480e4f185 commit: fe6608425e6217097aab82b89d4a72b79d94c8da Author: Luca Barbato gentoo org> AuthorDate: Thu Jul 29 14:24:27 2021 +0000 Commit: Georgy Yakovlev gentoo org> CommitDate: Wed Aug 25 15:11:28 2021 +0000 URL: https://gitweb.gentoo.org/proj/cargo-ebuild.git/commit/?id=fe660842 Add an option to provide a custom tera template Signed-off-by: Luca Barbato gentoo.org> Signed-off-by: Georgy Yakovlev gentoo.org> src/lib.rs | 12 ++++++++++-- src/main.rs | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2ecb1f3..8f53e17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,7 +123,11 @@ pub fn gen_ebuild_data(manifest_path: Option) -> Result { Ok(EbuildConfig::from_package(root_pkg, crates, licenses)) } -pub fn write_ebuild(ebuild_data: EbuildConfig, ebuild_path: impl AsRef) -> Result<()> { +pub fn write_ebuild( + ebuild_data: EbuildConfig, + ebuild_path: impl AsRef, + template_path: Option>, +) -> 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) -> 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, + #[structopt(name = "TEMPLATE", long = "template-path", short)] + /// Non-standard template + template_path: Option, } #[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);