Skip to main content

zoi_cli/cmd/package/
doctor.rs

1use anyhow::{Result, anyhow};
2use clap::Parser;
3use colored::Colorize;
4use std::path::PathBuf;
5
6#[derive(Parser, Debug)]
7pub struct DoctorCommand {
8    /// Path to the package file (e.g. path/to/name.pkg.lua)
9    #[arg(required = true)]
10    pub package_file: PathBuf,
11
12    /// Validate as this target platform (defaults to current platform)
13    #[arg(long)]
14    pub platform: Option<String>,
15
16    /// Override package version while validating
17    #[arg(long)]
18    pub version_override: Option<String>,
19}
20
21pub fn run(args: DoctorCommand) -> Result<()> {
22    println!(
23        "{} Running package doctor for {}",
24        "::".bold().blue(),
25        args.package_file.display()
26    );
27
28    let report = crate::pkg::package::doctor::run(
29        &args.package_file,
30        args.platform.as_deref(),
31        args.version_override.as_deref(),
32    )?;
33
34    for error in &report.errors {
35        eprintln!("{} {}", "Error:".red().bold(), error);
36    }
37
38    for warning in &report.warnings {
39        println!("{} {}", "Warning:".yellow().bold(), warning);
40    }
41
42    if report.errors.is_empty() {
43        println!(
44            "{} package doctor completed (warnings: {}).",
45            "::".bold().green(),
46            report.warnings.len()
47        );
48        Ok(())
49    } else {
50        Err(anyhow!(
51            "package doctor found {} error(s)",
52            report.errors.len()
53        ))
54    }
55}