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