systemprompt_cli/commands/web/validate/
mod.rs1pub mod asset_validation;
11mod config_validation;
12pub mod sitemap_validation;
13pub mod template_validation;
14
15use anyhow::{Context, Result};
16use clap::{Args, ValueEnum};
17
18use crate::CliConfig;
19use systemprompt_config::ProfileBootstrap;
20
21use super::paths::WebPaths;
22use super::types::ValidationOutput;
23
24#[derive(Debug, Clone, Copy, ValueEnum, Default)]
25pub enum ValidationCategory {
26 #[default]
27 All,
28 Config,
29 Templates,
30 Assets,
31 Sitemap,
32}
33
34#[derive(Debug, Clone, Copy, Args)]
35pub struct ValidateArgs {
36 #[arg(long, value_enum, help = "Only check specific category")]
37 pub only: Option<ValidationCategory>,
38}
39
40pub(super) fn execute(args: &ValidateArgs, _config: &CliConfig) -> Result<ValidationOutput> {
41 let profile = ProfileBootstrap::get().context("Failed to get profile")?;
42 let web_paths = WebPaths::resolve_from_profile(profile)?;
43
44 let mut errors = Vec::new();
45 let mut warnings = Vec::new();
46
47 let category = args.only.unwrap_or(ValidationCategory::All);
48
49 if matches!(
50 category,
51 ValidationCategory::All | ValidationCategory::Config
52 ) {
53 config_validation::validate_config(profile, &web_paths, &mut errors, &mut warnings);
54 }
55
56 if matches!(
57 category,
58 ValidationCategory::All | ValidationCategory::Templates
59 ) {
60 template_validation::validate_templates(profile, &web_paths, &mut errors, &mut warnings);
61 }
62
63 if matches!(
64 category,
65 ValidationCategory::All | ValidationCategory::Assets
66 ) {
67 asset_validation::validate_assets(profile, &web_paths, &mut errors, &mut warnings);
68 }
69
70 if matches!(
71 category,
72 ValidationCategory::All | ValidationCategory::Sitemap
73 ) {
74 sitemap_validation::validate_sitemap(profile, &mut errors, &mut warnings);
75 }
76
77 let valid = errors.is_empty();
78 let items_checked = match category {
79 ValidationCategory::All => 4,
80 _ => 1,
81 };
82
83 Ok(ValidationOutput {
84 valid,
85 items_checked,
86 errors,
87 warnings,
88 })
89}