Skip to main content

systemprompt_cli/shared/
mod.rs

1//! Cross-command CLI utilities shared across command modules.
2//!
3//! Aggregates the [`CommandOutput`] artifact model and its output types,
4//! profile resolution ([`resolve_profile_path`],
5//! [`resolve_profile_with_data`]), argument parsers, and text helpers. Also
6//! defines the `define_pool_command!` macro used by the log commands to
7//! generate pooled execution entry points.
8
9pub mod command_result;
10pub mod docker;
11pub mod parsers;
12pub mod paths;
13pub mod process;
14pub mod profile;
15pub mod project;
16pub mod text;
17
18pub use command_result::{
19    ChartType, CommandOutput, KeyValueItem, KeyValueOutput, SuccessOutput, TableOutput, TextOutput,
20    render_result,
21};
22pub use parsers::{parse_email, parse_profile_name};
23pub use profile::{
24    ProfileResolutionError, is_path_input, resolve_profile_from_path, resolve_profile_path,
25    resolve_profile_with_data,
26};
27pub use text::truncate_with_ellipsis;
28
29#[macro_export]
30macro_rules! define_pool_command {
31    ($args_ty:ty => $ret_ty:ty, with_config) => {
32        pub(in $crate::commands::infrastructure::logs) async fn execute(
33            args: $args_ty,
34            config: &$crate::CliConfig,
35        ) -> ::anyhow::Result<$ret_ty> {
36            let ctx = ::systemprompt_runtime::AppContext::new().await?;
37            let pool = ctx.db_pool().pool_arc()?;
38            execute_with_pool_inner(args, &pool, config).await
39        }
40
41        pub(in $crate::commands::infrastructure::logs) async fn execute_with_pool(
42            args: $args_ty,
43            db_ctx: &::systemprompt_runtime::DatabaseContext,
44            config: &$crate::CliConfig,
45        ) -> ::anyhow::Result<$ret_ty> {
46            let pool = db_ctx.db_pool().pool_arc()?;
47            execute_with_pool_inner(args, &pool, config).await
48        }
49    };
50    ($args_ty:ty => $ret_ty:ty, no_config) => {
51        pub(in $crate::commands::infrastructure::logs) async fn execute(
52            args: $args_ty,
53            _config: &$crate::CliConfig,
54        ) -> ::anyhow::Result<$ret_ty> {
55            let ctx = ::systemprompt_runtime::AppContext::new().await?;
56            let pool = ctx.db_pool().pool_arc()?;
57            execute_with_pool_inner(args, &pool).await
58        }
59
60        pub(in $crate::commands::infrastructure::logs) async fn execute_with_pool(
61            args: $args_ty,
62            db_ctx: &::systemprompt_runtime::DatabaseContext,
63            _config: &$crate::CliConfig,
64        ) -> ::anyhow::Result<$ret_ty> {
65            let pool = db_ctx.db_pool().pool_arc()?;
66            execute_with_pool_inner(args, &pool).await
67        }
68    };
69}