From 7cd4fc6c52b491c86b4109a6964dacc2ad08a156 Mon Sep 17 00:00:00 2001 From: Benno van den Berg Date: Thu, 16 May 2024 11:27:43 +0200 Subject: [PATCH] Allow adding published to the generated Cargo.toml (#208) * Allow adding published to the generated Cargo.toml * Change key to publish Update changelog --- CHANGELOG.md | 4 ++++ fp-bindgen/src/generators/mod.rs | 10 ++++++++++ fp-bindgen/src/generators/rust_plugin/mod.rs | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ebfa02..3d64356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format of this file is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## unreleased + +- Add ability to add `publish` to the generated Cargo.toml file (#208) + ## [3.0.0] - 2023-04-28 ### Added diff --git a/fp-bindgen/src/generators/mod.rs b/fp-bindgen/src/generators/mod.rs index 857e026..81a1225 100644 --- a/fp-bindgen/src/generators/mod.rs +++ b/fp-bindgen/src/generators/mod.rs @@ -68,6 +68,10 @@ pub struct RustPluginConfig { /// The license of the generated crate. pub license: Option, + + /// Whether the crate is marked as published or not (note: this should + /// the string value "true" or "false") + pub publish: Option, } impl RustPluginConfig { @@ -81,6 +85,7 @@ impl RustPluginConfig { description: None, readme: None, license: None, + publish: None, }, } } @@ -178,6 +183,11 @@ impl RustPluginConfigBuilder { self } + pub fn publish(mut self, value: bool) -> Self { + self.config.publish = Some(RustPluginConfigValue::String(value.to_string())); + self + } + pub fn dependency(mut self, name: impl Into, dependency: CargoDependency) -> Self { self.config.dependencies.insert(name.into(), dependency); self diff --git a/fp-bindgen/src/generators/rust_plugin/mod.rs b/fp-bindgen/src/generators/rust_plugin/mod.rs index f8074a4..f7d4c44 100644 --- a/fp-bindgen/src/generators/rust_plugin/mod.rs +++ b/fp-bindgen/src/generators/rust_plugin/mod.rs @@ -102,7 +102,7 @@ fn generate_cargo_file( format!( "[package] {}{}{}edition = \"2018\" -{}{}{} +{}{}{}{} [dependencies] {} ", @@ -112,6 +112,7 @@ fn generate_cargo_file( format_cargo_key("description", config.description), format_cargo_key("readme", config.readme), format_cargo_key("license", config.license), + format_cargo_key("publish", config.publish), dependencies .iter() .map(|(name, value)| format!("{name} = {value}"))