Skip to main content

objectiveai_sdk/cli/command/db/spawn/
mod.rs

1//! `db spawn` — 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.spawn.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.spawn.Path")]
15pub enum Path {
16    #[serde(rename = "db/spawn")]
17    DbSpawn,
18}
19impl CommandRequest for Request {
20    fn into_command(&self) -> Vec<String> {
21        let mut argv = vec!["db".to_string(), "spawn".to_string()];
22        self.base.push_flags(&mut argv);
23        argv
24    }
25
26    fn request_base(&self) -> &crate::cli::command::RequestBase {
27        &self.base
28    }
29
30    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
31        Some(&mut self.base)
32    }
33}
34
35#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
36#[schemars(rename = "cli.command.db.spawn.Response")]
37pub struct Response {
38    pub listening: String,
39}
40
41#[derive(clap::Args)]
42pub struct Args {
43    #[command(flatten)]
44    pub base: crate::cli::command::RequestBaseArgs,
45}
46
47#[derive(clap::Args)]
48#[command(args_conflicts_with_subcommands = true)]
49pub struct Command {
50    #[command(flatten)]
51    pub args: Args,
52    #[command(subcommand)]
53    pub schema: Option<Schema>,
54}
55
56#[derive(clap::Subcommand)]
57pub enum Schema {
58    /// Emit the JSON Schema for this leaf's `Request` type and exit.
59    RequestSchema(request_schema::Args),
60    /// Emit the JSON Schema for this leaf's `Response` type and exit.
61    ResponseSchema(response_schema::Args),
62}
63
64impl TryFrom<Args> for Request {
65    type Error = crate::cli::command::FromArgsError;
66    fn try_from(args: Args) -> Result<Self, Self::Error> {
67        Ok(Self { path_type: Path::DbSpawn, base: args.base.into() })
68    }
69}
70
71#[cfg(feature = "cli-executor")]
72pub async fn execute<E: crate::cli::command::CommandExecutor>(
73    executor: &E,
74    mut request: Request,
75
76        agent_arguments: Option<&crate::cli::command::AgentArguments>,
77    ) -> Result<Response, E::Error> {
78    request.base.clear_transform();
79    executor.execute_one(request, agent_arguments).await
80}
81
82#[cfg(feature = "cli-executor")]
83pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
84    executor: &E,
85    mut request: Request,
86    transform: crate::cli::command::Transform,
87
88        agent_arguments: Option<&crate::cli::command::AgentArguments>,
89    ) -> Result<serde_json::Value, E::Error> {
90    request.base.set_transform(transform);
91    executor.execute_one(request, agent_arguments).await
92}
93
94#[cfg(feature = "mcp")]
95impl crate::cli::command::CommandResponse for Response {
96    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
97        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
98    }
99}
100
101pub mod request_schema;
102
103pub mod response_schema;