Skip to main content

objectiveai_sdk/cli/command/swarms/get/
mod.rs

1//! `swarms 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.swarms.get.Request")]
7pub struct Request {
8    pub path_type: Path,
9    pub path: crate::RemotePathCommitOptional,
10    #[serde(flatten)]
11    pub base: crate::cli::command::RequestBase,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.swarms.get.Path")]
16pub enum Path {
17    #[serde(rename = "swarms/get")]
18    SwarmsGet,
19}
20
21impl CommandRequest for Request {
22    fn into_command(&self) -> Vec<String> {
23        let mut argv = vec![
24            "swarms".to_string(),
25            "get".to_string(),
26            "--path".to_string(),
27            crate::cli::command::path_ref::remote_path_to_arg_string(&self.path),
28        ];
29        self.base.push_flags(&mut argv);
30        argv
31    }
32
33    fn request_base(&self) -> &crate::cli::command::RequestBase {
34        &self.base
35    }
36
37    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
38        Some(&mut self.base)
39    }
40}
41
42/// Response for `swarms get` — a Swarm base definition with its remote path.
43#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
44#[schemars(rename = "cli.command.swarms.get.Response")]
45pub struct Response {
46    #[serde(flatten)]
47    #[schemars(schema_with = "crate::flatten_schema::<crate::RemotePath>")]
48    pub path: crate::RemotePath,
49    /// The Swarm base definition.
50    #[serde(flatten)]
51    #[schemars(schema_with = "crate::flatten_schema::<crate::swarm::RemoteSwarmBase>")]
52    pub inner: crate::swarm::RemoteSwarmBase,
53}
54
55#[cfg(feature = "mcp")]
56impl crate::cli::command::CommandResponse for Response {
57    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
58        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
59    }
60}
61
62#[derive(clap::Args)]
63pub struct Args {
64    /// Path to the target entry.
65    #[arg(long)]
66    pub path: String,
67    #[command(flatten)]
68    pub base: crate::cli::command::RequestBaseArgs,
69}
70
71#[derive(clap::Args)]
72#[command(args_conflicts_with_subcommands = true)]
73pub struct Command {
74    #[command(flatten)]
75    pub args: Args,
76    #[command(subcommand)]
77    pub schema: Option<Schema>,
78}
79
80#[derive(clap::Subcommand)]
81pub enum Schema {
82    /// Emit the JSON Schema for this leaf's `Request` type and exit.
83    RequestSchema(request_schema::Args),
84    /// Emit the JSON Schema for this leaf's `Response` type and exit.
85    ResponseSchema(response_schema::Args),
86}
87
88impl TryFrom<Args> for Request {
89    type Error = crate::cli::command::FromArgsError;
90    fn try_from(args: Args) -> Result<Self, Self::Error> {
91        let path = args
92            .path
93            .parse::<crate::RemotePathCommitOptional>()
94            .map_err(|msg| crate::cli::command::FromArgsError::path_parse("path", msg))?;
95        Ok(Self { path_type: Path::SwarmsGet, path, base: args.base.into() })
96    }
97}
98
99#[cfg(feature = "cli-executor")]
100pub async fn execute<E: crate::cli::command::CommandExecutor>(
101    executor: &E,
102    mut request: Request,
103
104        agent_arguments: Option<&crate::cli::command::AgentArguments>,
105    ) -> Result<Response, E::Error> {
106    request.base.clear_transform();
107    executor.execute_one(request, agent_arguments).await
108}
109
110#[cfg(feature = "cli-executor")]
111pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
112    executor: &E,
113    mut request: Request,
114    transform: crate::cli::command::Transform,
115
116        agent_arguments: Option<&crate::cli::command::AgentArguments>,
117    ) -> Result<serde_json::Value, E::Error> {
118    request.base.set_transform(transform);
119    executor.execute_one(request, agent_arguments).await
120}
121
122pub mod request_schema;
123
124
125pub mod response_schema;