Skip to main content

systemprompt_cli/commands/plugins/capabilities/
schemas.rs

1use clap::Args;
2
3use crate::CliConfig;
4use crate::commands::plugins::discover_registry;
5use crate::commands::plugins::types::{SchemaWithExtension, SchemasListOutput};
6use crate::shared::CommandOutput;
7
8#[derive(Debug, Clone, Args)]
9pub struct SchemasArgs {
10    #[arg(long, help = "Filter by extension ID")]
11    pub extension: Option<String>,
12}
13
14pub fn execute(args: &SchemasArgs, _config: &CliConfig) -> CommandOutput {
15    let registry = discover_registry();
16
17    let schemas: Vec<SchemaWithExtension> = registry
18        .extensions()
19        .iter()
20        .filter(|ext| args.extension.as_ref().is_none_or(|f| ext.id().contains(f)))
21        .flat_map(|ext| {
22            ext.schemas()
23                .iter()
24                .map(|schema| SchemaWithExtension {
25                    extension_id: systemprompt_identifiers::PluginId::new(ext.id()),
26                    extension_name: ext.name().to_owned(),
27                    table: schema.table.clone(),
28                    source: "inline".to_owned(),
29                })
30                .collect::<Vec<_>>()
31        })
32        .collect();
33
34    let total = schemas.len();
35
36    let output = SchemasListOutput { schemas, total };
37
38    CommandOutput::table_of(vec!["extension_id", "table", "source"], &output.schemas)
39        .with_title("Schemas Across Extensions")
40}