Skip to main content

systemprompt_cli/commands/web/templates/
mod.rs

1//! Management of HTML templates and their content-type bindings.
2//!
3//! Dispatches the `web templates` subcommands ([`TemplatesCommands`]) to list,
4//! show, create, edit, and delete templates in the web templates config.
5//!
6//! Copyright (c) systemprompt.io — Business Source License 1.1.
7//! See <https://systemprompt.io> for licensing details.
8
9pub mod create;
10pub mod delete;
11pub mod edit;
12pub mod list;
13pub mod selection;
14pub mod show;
15
16use anyhow::{Context, Result};
17use clap::Subcommand;
18
19use crate::CliConfig;
20use crate::interactive::Prompter;
21use crate::shared::render_result;
22
23#[derive(Debug, Subcommand)]
24pub enum TemplatesCommands {
25    #[command(about = "List all templates")]
26    List(list::ListArgs),
27
28    #[command(about = "Show template details")]
29    Show(show::ShowArgs),
30
31    #[command(about = "Create a new template")]
32    Create(create::CreateArgs),
33
34    #[command(about = "Edit a template")]
35    Edit(edit::EditArgs),
36
37    #[command(about = "Delete a template")]
38    Delete(delete::DeleteArgs),
39}
40
41pub fn execute(
42    command: TemplatesCommands,
43    prompter: &dyn Prompter,
44    config: &CliConfig,
45) -> Result<()> {
46    match command {
47        TemplatesCommands::List(args) => {
48            let result = list::execute(args, config).context("Failed to list templates")?;
49            render_result(&result, config);
50            Ok(())
51        },
52        TemplatesCommands::Show(args) => {
53            let result =
54                show::execute(args, prompter, config).context("Failed to show template")?;
55            render_result(&result, config);
56            Ok(())
57        },
58        TemplatesCommands::Create(args) => {
59            let result =
60                create::execute(args, prompter, config).context("Failed to create template")?;
61            render_result(&result, config);
62            Ok(())
63        },
64        TemplatesCommands::Edit(args) => {
65            let result =
66                edit::execute(args, prompter, config).context("Failed to edit template")?;
67            render_result(&result, config);
68            Ok(())
69        },
70        TemplatesCommands::Delete(args) => {
71            let result =
72                delete::execute(args, prompter, config).context("Failed to delete template")?;
73            render_result(&result, config);
74            Ok(())
75        },
76    }
77}