Skip to main content

objectiveai_sdk/cli/command/db/config/get/
mod.rs

1//! `config db get` — async handler stub.
2
3use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.db.config.get.Request")]
7pub struct Request {
8    pub path_type: Path,
9    #[serde(flatten)]
10    pub base: crate::cli::command::RequestBase,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.db.config.get.Path")]
15pub enum Path {
16    #[serde(rename = "db/config/get")]
17    DbConfigGet,
18}
19
20impl CommandRequest for Request {
21    fn request_base(&self) -> &crate::cli::command::RequestBase {
22        &self.base
23    }
24
25    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
26        Some(&mut self.base)
27    }
28}
29
30#[derive(PartialEq, Debug, Clone, Default, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
31#[schemars(rename = "cli.command.db.config.get.Response")]
32pub struct Response {
33    #[serde(skip_serializing_if = "Option::is_none")]
34    #[schemars(extend("omitempty" = true))]
35    pub address: Option<String>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    #[schemars(extend("omitempty" = true))]
38    pub user: Option<String>,
39    #[serde(skip_serializing_if = "Option::is_none")]
40    #[schemars(extend("omitempty" = true))]
41    pub password: Option<String>,
42    #[serde(skip_serializing_if = "Option::is_none")]
43    #[schemars(extend("omitempty" = true))]
44    pub database: Option<String>,
45}
46
47#[derive(clap::Args)]
48pub struct Args {
49    #[command(flatten)]
50    pub base: crate::cli::command::RequestBaseArgs,
51}
52
53#[derive(clap::Args)]
54#[command(args_conflicts_with_subcommands = true)]
55pub struct Command {
56    #[command(flatten)]
57    pub args: Args,
58    #[command(subcommand)]
59    pub schema: Option<Schema>,
60}
61
62#[derive(clap::Subcommand)]
63pub enum Schema {
64    /// Emit the JSON Schema for this leaf's `Request` type and exit.
65    RequestSchema(request_schema::Args),
66    /// Emit the JSON Schema for this leaf's `Response` type and exit.
67    ResponseSchema(response_schema::Args),
68}
69
70impl TryFrom<Args> for Request {
71    type Error = crate::cli::command::FromArgsError;
72    fn try_from(args: Args) -> Result<Self, Self::Error> {
73        Ok(Self { path_type: Path::DbConfigGet,
74            base: args.base.into(),
75        })
76    }
77}
78
79#[cfg(feature = "cli-executor")]
80pub async fn execute<E: crate::cli::command::CommandExecutor>(
81    executor: &E,
82    mut request: Request,
83
84        agent_arguments: Option<&crate::cli::command::AgentArguments>,
85    ) -> Result<Response, E::Error> {
86    request.base.clear_transform();
87    executor.execute_one(request, agent_arguments).await
88}
89
90#[cfg(feature = "cli-executor")]
91pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
92    executor: &E,
93    mut request: Request,
94    transform: crate::cli::command::Transform,
95
96        agent_arguments: Option<&crate::cli::command::AgentArguments>,
97    ) -> Result<serde_json::Value, E::Error> {
98    request.base.set_transform(transform);
99    executor.execute_one(request, agent_arguments).await
100}
101
102#[cfg(feature = "mcp")]
103impl crate::cli::command::CommandResponse for Response {
104    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
105        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
106    }
107}
108
109pub mod request_schema;
110
111pub mod response_schema;
112
113/// One `/listen` broadcast run of `db config get`: the actual
114/// [`Request`], the producer's
115/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
116/// unary response future. See [`crate::cli::broadcast_listener`].
117#[cfg(feature = "cli-listener")]
118pub struct ListenerExecution {
119    pub request: Request,
120    pub agent_arguments: crate::cli::command::AgentArguments,
121    pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
122}