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