Skip to main content

systemprompt_cli/commands/core/contexts/
mod.rs

1//! `core contexts` command group: manage conversation contexts.
2//!
3//! Dispatches the [`ContextsCommands`] subcommands (list, show, create, edit,
4//! delete, use, new) that create contexts and set the session's active one.
5
6mod create;
7pub(crate) mod delete;
8mod edit;
9mod list;
10mod new;
11mod resolve;
12mod show;
13mod types;
14mod use_context;
15
16use crate::cli_settings::CliConfig;
17use crate::shared::render_result;
18use anyhow::Result;
19use clap::Subcommand;
20
21pub use types::*;
22
23#[derive(Debug, Subcommand)]
24pub enum ContextsCommands {
25    #[command(about = "List all contexts with stats")]
26    List(list::ListArgs),
27
28    #[command(about = "Show context details")]
29    Show(show::ShowArgs),
30
31    #[command(about = "Create a new context")]
32    Create(create::CreateArgs),
33
34    #[command(about = "Rename a context")]
35    Edit(edit::EditArgs),
36
37    #[command(about = "Delete a context")]
38    Delete(delete::DeleteArgs),
39
40    #[command(name = "use", about = "Set session's active context")]
41    Use(use_context::UseArgs),
42
43    #[command(about = "Create a new context and set it as active")]
44    New(new::NewArgs),
45}
46
47pub async fn execute(cmd: ContextsCommands, config: &CliConfig) -> Result<()> {
48    match cmd {
49        ContextsCommands::List(args) => {
50            let result = list::execute(args, config).await?;
51            render_result(&result);
52        },
53        ContextsCommands::Show(args) => {
54            let result = show::execute(args, config).await?;
55            render_result(&result);
56        },
57        ContextsCommands::Create(args) => {
58            let result = create::execute(args, config).await?;
59            render_result(&result);
60        },
61        ContextsCommands::Edit(args) => {
62            let result = edit::execute(args, config).await?;
63            render_result(&result);
64        },
65        ContextsCommands::Delete(args) => {
66            let result = delete::execute(args, config).await?;
67            render_result(&result);
68        },
69        ContextsCommands::Use(args) => {
70            let result = use_context::execute(args, config).await?;
71            render_result(&result);
72        },
73        ContextsCommands::New(args) => {
74            let result = new::execute(args, config).await?;
75            render_result(&result);
76        },
77    }
78    Ok(())
79}