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
6pub mod create;
7pub mod delete;
8pub mod edit;
9pub mod list;
10pub mod selection;
11pub mod show;
12
13use anyhow::{Context, Result};
14use clap::Subcommand;
15
16use crate::CliConfig;
17use crate::interactive::Prompter;
18use crate::shared::render_result;
19
20#[derive(Debug, Subcommand)]
21pub enum TemplatesCommands {
22    #[command(about = "List all templates")]
23    List(list::ListArgs),
24
25    #[command(about = "Show template details")]
26    Show(show::ShowArgs),
27
28    #[command(about = "Create a new template")]
29    Create(create::CreateArgs),
30
31    #[command(about = "Edit a template")]
32    Edit(edit::EditArgs),
33
34    #[command(about = "Delete a template")]
35    Delete(delete::DeleteArgs),
36}
37
38pub fn execute(
39    command: TemplatesCommands,
40    prompter: &dyn Prompter,
41    config: &CliConfig,
42) -> Result<()> {
43    match command {
44        TemplatesCommands::List(args) => {
45            let result = list::execute(args, config).context("Failed to list templates")?;
46            render_result(&result, config);
47            Ok(())
48        },
49        TemplatesCommands::Show(args) => {
50            let result =
51                show::execute(args, prompter, config).context("Failed to show template")?;
52            render_result(&result, config);
53            Ok(())
54        },
55        TemplatesCommands::Create(args) => {
56            let result =
57                create::execute(args, prompter, config).context("Failed to create template")?;
58            render_result(&result, config);
59            Ok(())
60        },
61        TemplatesCommands::Edit(args) => {
62            let result =
63                edit::execute(args, prompter, config).context("Failed to edit template")?;
64            render_result(&result, config);
65            Ok(())
66        },
67        TemplatesCommands::Delete(args) => {
68            let result =
69                delete::execute(args, prompter, config).context("Failed to delete template")?;
70            render_result(&result, config);
71            Ok(())
72        },
73    }
74}