Add metadata generator and CLI integration

This commit is contained in:
m00d 2025-10-01 07:26:20 +02:00
parent 205ab25d41
commit c19c5c21ab
6 changed files with 291 additions and 1 deletions

View file

@ -13,6 +13,8 @@ use serde_json::{Value, json};
use sha2::{Digest, Sha256};
use walkdir::WalkDir;
use package_management::pkgs::generator;
#[derive(Parser)]
#[command(
name = "metadata-indexer",
@ -64,6 +66,18 @@ enum Command {
#[arg(long)]
dry_run: bool,
},
/// Generate Rust modules from harvested metadata
Generate {
/// Path to the harvested metadata JSON file
#[arg(long)]
metadata: PathBuf,
/// Output directory (should be the `by_name` root)
#[arg(long, default_value = "src/pkgs/by_name")]
output: PathBuf,
/// Remove existing module directory before regeneration
#[arg(long)]
overwrite: bool,
},
}
fn main() -> Result<()> {
@ -221,6 +235,31 @@ fn main() -> Result<()> {
println!("No manifests refreshed (check warnings above).");
}
}
Command::Generate {
metadata,
output,
overwrite,
} => {
if overwrite {
match generator::module_directory(&metadata, &output) {
Ok(dir) if dir.exists() => {
fs::remove_dir_all(&dir).with_context(|| {
format!("removing existing module {}", dir.display())
})?;
}
Ok(_) => {}
Err(err) => {
eprintln!(
"warning: could not determine existing module directory: {}",
err
);
}
}
}
let module_path = generator::generate_module(&metadata, &output)?;
println!("Generated module at {}", module_path.display());
}
}
Ok(())