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/// Doctor command module.
14pub mod doctor;
15/// Init-LSP command module.
16pub mod init_lsp;
17/// Inspect command module.
18pub mod inspect;
19/// Install command module.
20pub mod install;
21/// Test command module.
22pub mod test;
23
24/// Arguments for the `package` command.
25#[derive(Parser, Debug)]
26pub struct PackageCommand {
27 /// The package sub-command to run.
28 #[command(subcommand)]
29 command: Commands
30}
31
32/// Available package sub-commands.
33#[derive(Subcommand, Debug)]
34enum Commands {
35 /// Build a package from a pkg.lua file
36 Build(build::BuildCommand),
37 /// Bundle a package and its local assets into a .zsa archive
38 Bundle(bundle::BundleCommand),
39 /// Test a package from a pkg.lua file
40 Test(build::BuildCommand),
41 /// Install a package from a local archive
42 Install(install::InstallCommand),
43 /// Lint and validate a package definition for maintainers
44 Doctor(doctor::DoctorCommand),
45 /// Initialize LSP support for .pkg.lua files
46 InitLsp(init_lsp::InitLspCommand),
47 /// Inspect a package definition and output metadata
48 Inspect(inspect::InspectCommand)
49}
50
51/// Runs the package command.
52///
53/// # Errors
54///
55/// Returns an error if the subcommand execution fails.
56pub fn run(args: PackageCommand) -> Result<()> {
57 match args.command {
58 Commands::Build(cmd) => build::run(cmd),
59 Commands::Bundle(cmd) => bundle::run(cmd),
60 Commands::Test(cmd) => test::run(&cmd),
61 Commands::Install(cmd) => install::run(cmd),
62 Commands::Doctor(cmd) => doctor::run(&cmd),
63 Commands::InitLsp(cmd) => init_lsp::run(&cmd),
64 Commands::Inspect(cmd) => inspect::run(cmd)
65 }
66}