diff --git a/crates/crunch-cli/src/main.rs b/crates/crunch-cli/src/main.rs index 17b7142..8ff03e1 100644 --- a/crates/crunch-cli/src/main.rs +++ b/crates/crunch-cli/src/main.rs @@ -109,15 +109,13 @@ async fn main() -> anyhow::Result<()> { ) .with_default("src/gencrunch") .prompt()?; + let entity = inquire::Text::new("entity") + .with_help_message("please set which entity you want to publish for") + .with_default("example") + .prompt_skippable()?; - let bootstrap_schema = inquire::Confirm::new("bootstrap schema file") - .with_help_message( - "will create an example protobuf file in the supplied schema_path", - ) - .with_default(true) - .prompt()?; - if bootstrap_schema { - let config = config.add_publish(&schema_path, &output_path); + if let Some(entity) = entity { + let config = config.add_publish(&schema_path, &output_path, &[&entity]); config.write_file(&cli.global_args.crunch_file).await?; let schema_output_path = cli @@ -126,7 +124,7 @@ async fn main() -> anyhow::Result<()> { .parent() .unwrap_or(&PathBuf::from("")) .join(&schema_path) - .join("event.proto"); + .join(format!("{}.proto", entity)); if let Some(dir) = schema_output_path.parent() { if !dir.exists() { tokio::fs::create_dir_all(dir).await?; @@ -146,7 +144,7 @@ message MyEvent {{ string my_field = 1; }} "#, - config.service.domain, config.service.service + config.service.domain, entity ) .as_bytes(), ) diff --git a/crates/crunch-file/src/lib.rs b/crates/crunch-file/src/lib.rs index 7ce6a3c..93d7ca0 100644 --- a/crates/crunch-file/src/lib.rs +++ b/crates/crunch-file/src/lib.rs @@ -26,6 +26,7 @@ pub struct Publish { pub schema_path: String, #[serde(alias = "output-path")] pub output_path: String, + pub entities: Vec, } #[allow(dead_code)] @@ -65,11 +66,22 @@ impl File { Ok(content) } - pub fn add_publish(&mut self, schema_path: &str, output_path: &str) -> &mut Self { + pub fn add_publish( + &mut self, + schema_path: &str, + output_path: &str, + entities: &[&str], + ) -> &mut Self { let mut publish = toml_edit::Table::new(); publish["schema-path"] = value(schema_path); publish["output-path"] = value(output_path); + let mut entities_arr = toml_edit::Array::new(); + for entity in entities { + entities_arr.push(entity.to_string()); + } + publish["entities"] = value(entities_arr); + if !self.doc.contains_key("publish") { tracing::debug!("publish key not existing, adding new"); self.doc["publish"] = toml_edit::array() @@ -141,7 +153,7 @@ schema-path = "some-schema" output-path = "some-output" "#; let mut config = File::parse(raw).await?; - let config = config.add_publish("some-schema", "some-output"); + let config = config.add_publish("some-schema", "some-output", &[]); let output = config.write().await?; pretty_assertions::assert_eq!(output, expected); @@ -166,7 +178,7 @@ schema-path = "some-schema" output-path = "some-output" "#; let mut config = File::parse(raw).await?; - let config = config.add_publish("some-schema", "some-output"); + let config = config.add_publish("some-schema", "some-output", &[]); let output = config.write().await?; pretty_assertions::assert_eq!(output, expected);