Skip to main content

systemprompt_cli/commands/web/
mod.rs

1//! The `web` command group: configuration management for the static-site layer.
2//!
3//! Routes [`WebCommands`] to the content-type, template, asset, sitemap, and
4//! validation subcommands, each operating on the on-disk web content config.
5//!
6//! Copyright (c) systemprompt.io — Business Source License 1.1.
7//! See <https://systemprompt.io> for licensing details.
8
9pub mod assets;
10pub mod content_types;
11pub mod paths;
12pub mod sitemap;
13pub mod templates;
14pub mod types;
15pub mod validate;
16
17use anyhow::Result;
18use clap::Subcommand;
19
20use crate::context::CommandContext;
21use crate::shared::{CommandOutput, render_result};
22
23#[derive(Debug, Subcommand)]
24pub enum WebCommands {
25    #[command(subcommand, about = "Manage content types")]
26    ContentTypes(content_types::ContentTypesCommands),
27
28    #[command(subcommand, about = "Manage templates")]
29    Templates(templates::TemplatesCommands),
30
31    #[command(subcommand, about = "List and inspect assets")]
32    Assets(assets::AssetsCommands),
33
34    #[command(subcommand, about = "Sitemap operations")]
35    Sitemap(sitemap::SitemapCommands),
36
37    #[command(about = "Validate web configuration")]
38    Validate(validate::ValidateArgs),
39}
40
41pub fn execute(command: WebCommands, ctx: &CommandContext) -> Result<()> {
42    let config = &ctx.cli;
43    match command {
44        WebCommands::ContentTypes(cmd) => content_types::execute(cmd, ctx.prompter(), config),
45        WebCommands::Templates(cmd) => templates::execute(cmd, ctx.prompter(), config),
46        WebCommands::Assets(cmd) => assets::execute(cmd, config),
47        WebCommands::Sitemap(cmd) => sitemap::execute(cmd, config),
48        WebCommands::Validate(args) => {
49            let output = validate::execute(&args, config)?;
50            let valid = output.valid;
51            let error_count = output.errors.len();
52            render_result(
53                &CommandOutput::card_value("Web Configuration Validation", &output),
54                config,
55            );
56            if !valid {
57                return Err(anyhow::anyhow!(
58                    "web configuration is invalid: {error_count} error(s), see report above",
59                ));
60            }
61            Ok(())
62        },
63    }
64}