Skip to main content

zoi_cli/cmd/package/
mod.rs

1//! Package development and maintenance commands.
2//!
3//! This module provides tools for package maintainers to build, test, bundle,
4//! and validate Zoi packages.
5
6use anyhow::Result;
7use clap::{Parser, Subcommand};
8
9/// Build command module.
10pub mod build;
11/// Bundle command module.
12pub mod bundle;
13/// Delta generation command module.
14pub mod delta;
15/// Doctor command module.
16pub mod doctor;
17/// Init-LSP command module.
18pub mod init_lsp;
19/// Inspect command module.
20pub mod inspect;
21/// Install command module.
22pub mod install;
23/// Test command module.
24pub mod test;
25/// Verify command module.
26pub mod verify;
27
28/// Arguments for the `package` command.
29#[derive(Parser, Debug)]
30pub struct PackageCommand {
31    /// The package sub-command to run.
32    #[command(subcommand)]
33    command: Commands
34}
35
36/// Available package sub-commands.
37#[derive(Subcommand, Debug)]
38enum Commands {
39    /// Build a package from a pkg.lua file
40    Build(build::BuildCommand),
41    /// Bundle a package and its local assets into a .zsa archive
42    Bundle(bundle::BundleCommand),
43    /// Test a package from a pkg.lua file
44    Test(build::BuildCommand),
45    /// Install a package from a local archive
46    Install(install::InstallCommand),
47    /// Generate a delta patch between two package archives
48    Delta(delta::DeltaCommand),
49    /// Verify the integrity of installed packages or an archive
50    Verify(verify::VerifyCommand),
51    /// Lint and validate a package definition for maintainers
52    Doctor(doctor::DoctorCommand),
53    /// Initialize LSP support for .pkg.lua files
54    InitLsp(init_lsp::InitLspCommand),
55    /// Inspect a package definition and output metadata
56    Inspect(inspect::InspectCommand)
57}
58
59/// Runs the package command.
60///
61/// # Errors
62///
63/// Returns an error if the subcommand execution fails.
64pub fn run(args: PackageCommand) -> Result<()> {
65    match args.command {
66        Commands::Build(cmd) => build::run(cmd),
67        Commands::Bundle(cmd) => bundle::run(cmd),
68        Commands::Test(cmd) => test::run(&cmd),
69        Commands::Install(cmd) => install::run(cmd),
70        Commands::Delta(cmd) => delta::run(&cmd),
71        Commands::Verify(cmd) => verify::run(&cmd),
72        Commands::Doctor(cmd) => doctor::run(&cmd),
73        Commands::InitLsp(cmd) => init_lsp::run(&cmd),
74        Commands::Inspect(cmd) => inspect::run(cmd)
75    }
76}