Skip to main content

systemprompt_cli/commands/web/templates/
selection.rs

1//! Interactive template selection.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use anyhow::{Result, anyhow};
7
8use crate::interactive::Prompter;
9
10use super::super::types::TemplatesConfig;
11
12pub fn prompt_template_selection(
13    prompter: &dyn Prompter,
14    config: &TemplatesConfig,
15    prompt: &str,
16) -> Result<String> {
17    let mut names: Vec<String> = config.templates.keys().cloned().collect();
18    names.sort();
19
20    if names.is_empty() {
21        return Err(anyhow!("No templates configured"));
22    }
23
24    let selection = prompter.select(prompt, &names)?;
25    Ok(names[selection].clone())
26}