From 0e41523ea5dc5b161de1f5fbf05235914e4c2f87 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Mon, 13 Apr 2026 14:15:33 +0200 Subject: [PATCH] Introduce --flat option to MLF generation `mlf generate lexicon` has a `--flat` option to generate a lexicon file without any nesting. So intead of generating `com/example/forum/thread.json`, it generates `com.example.forum.thread.json`. This commit adds the same `--flat` option to generate MLF files via `mlf generate mlf`, hence generating `com.example.forum.thread.mlf` instead of `com.example.forum.thread.mlf`. --- mlf-cli/src/generate/mlf.rs | 33 +++++++++++++++++++-------------- mlf-cli/src/main.rs | 7 +++++-- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/mlf-cli/src/generate/mlf.rs b/mlf-cli/src/generate/mlf.rs index 83310fe..0c1c0ed 100644 --- a/mlf-cli/src/generate/mlf.rs +++ b/mlf-cli/src/generate/mlf.rs @@ -51,7 +51,7 @@ pub enum MlfGenerateError { }, } -pub fn run(input_patterns: Vec, output_dir: Option) -> Result<(), MlfGenerateError> { +pub fn run(input_patterns: Vec, output_dir: Option, flat: bool) -> Result<(), MlfGenerateError> { let current_dir = std::env::current_dir().map_err(|source| MlfGenerateError::WriteOutput { path: "current directory".to_string(), source, @@ -147,19 +147,24 @@ pub fn run(input_patterns: Vec, output_dir: Option) -> Result<( message: "Missing 'id' field in lexicon".to_string(), })?; - // Create output path from namespace - let mut output_path = output_dir.clone(); - for segment in namespace.split('.') { - output_path.push(segment); - } - if let Err(source) = std::fs::create_dir_all(&output_path.parent().unwrap()) { - errors.push(( - file_path.display().to_string(), - format!("Failed to create directory: {}", source), - )); - continue; - } - output_path.set_extension("mlf"); + let output_path = if flat { + output_dir.join(format!("{}.mlf", namespace)) + } else { + // Create output path from namespace + let mut path = output_dir.clone(); + for segment in namespace.split('.') { + path.push(segment); + } + if let Err(source) = std::fs::create_dir_all(&path.parent().unwrap()) { + errors.push(( + file_path.display().to_string(), + format!("Failed to create directory: {}", source), + )); + continue; + } + path.set_extension("mlf"); + path + }; if let Err(source) = std::fs::write(&output_path, mlf_content) { errors.push(( diff --git a/mlf-cli/src/main.rs b/mlf-cli/src/main.rs index 4575387..ed7a7d5 100644 --- a/mlf-cli/src/main.rs +++ b/mlf-cli/src/main.rs @@ -109,6 +109,9 @@ enum GenerateCommands { #[arg(short, long, help = "Output directory. If omitted, uses first mlf output from mlf.toml")] output: Option, + + #[arg(long, help = "Use flat file structure (e.g., app.bsky.post.json)")] + flat: bool, }, } @@ -133,8 +136,8 @@ async fn main() { Some(GenerateCommands::Code { generator, input, output, root, flat }) => { generate::code::run(generator, input, output, root, flat).into_diagnostic() } - Some(GenerateCommands::Mlf { input, output }) => { - generate::mlf::run(input, output).into_diagnostic() + Some(GenerateCommands::Mlf { input, output, flat }) => { + generate::mlf::run(input, output, flat).into_diagnostic() } None => { // Run all outputs from mlf.toml -- 2.51.2