Skip to main content

zoi_cli/cmd/
registry.rs

1use anyhow::Result;
2use clap::{Parser, Subcommand};
3
4#[derive(Parser, Debug)]
5pub struct RegistryCommand {
6    #[command(subcommand)]
7    pub command: RegistryCommands,
8}
9
10#[derive(Subcommand, Debug)]
11pub enum RegistryCommands {
12    /// Initialize a new Zoi registry
13    Init {
14        /// Path where the registry should be initialized
15        #[arg(default_value = ".")]
16        path: std::path::PathBuf,
17    },
18    /// Generate metadata files (packages.json and advisories.json)
19    #[command(alias = "gen-meta")]
20    GenerateMetadata,
21    /// Check registry integrity and validate packages
22    #[command(aliases = ["lint", "audit"])]
23    Check,
24    /// Add a new package to the registry
25    #[command(alias = "add-pkg")]
26    AddPackage {
27        /// Name of the package to add
28        name: Option<String>,
29        /// Repository tier (e.g. community, main)
30        #[arg(long, short)]
31        repo: Option<String>,
32    },
33    /// Add a new security advisory for a package
34    #[command(alias = "sec")]
35    AddAdvisory {
36        /// Package name to add an advisory for
37        package: Option<String>,
38        /// Repository tier (e.g. community, main)
39        #[arg(long, short)]
40        repo: Option<String>,
41    },
42}
43
44pub fn run(args: RegistryCommand) -> Result<()> {
45    let registry_root = std::path::Path::new(".");
46    match args.command {
47        RegistryCommands::Init { path } => crate::pkg::registry::init(&path),
48        RegistryCommands::GenerateMetadata => {
49            crate::pkg::registry::generate_metadata(registry_root)
50        }
51        RegistryCommands::Check => crate::pkg::registry::check(registry_root),
52        RegistryCommands::AddPackage { name, repo } => {
53            crate::pkg::registry::add_package(registry_root, name.as_deref(), repo.as_deref())
54        }
55        RegistryCommands::AddAdvisory { package, repo } => {
56            crate::pkg::registry::add_advisory(registry_root, package.as_deref(), repo.as_deref())
57        }
58    }
59}