Skip to main content

objectiveai_sdk/cli/command/config/swarms/favorites/add/
mod.rs

1//! `config swarms favorites add` — async handler stub.
2
3use crate::RemotePathCommitOptional;
4use crate::cli::command::CommandRequest;
5
6#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
7#[schemars(rename = "cli.command.config.swarms.favorites.add.Request")]
8pub struct Request {
9    pub path_type: Path,
10    pub name: String,
11    pub path: RemotePathCommitOptional,
12    pub note: String,
13}
14
15#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
16#[schemars(rename = "cli.command.config.swarms.favorites.add.Path")]
17pub enum Path {
18    #[serde(rename = "config/swarms/favorites/add")]
19    ConfigSwarmsFavoritesAdd,
20}
21
22impl CommandRequest for Request {
23    fn into_command(&self) -> Vec<String> {
24        vec![
25            "config".to_string(),
26            "swarms".to_string(),
27            "favorites".to_string(),
28            "add".to_string(),
29            "--name".to_string(),
30            self.name.clone(),
31            "--path".to_string(),
32            crate::cli::command::remote_path_to_arg_string(&self.path),
33            "--note".to_string(),
34            self.note.clone(),
35        ]
36    }
37}
38
39pub type Response = crate::cli::command::Ok;
40
41#[derive(clap::Args)]
42pub struct Args {
43    /// Favorite name.
44    #[arg(long)]
45    pub name: String,
46    /// Remote-path string (docker-style: `remote=<github|filesystem|mock>,owner=…,repository=…[,commit=…]`).
47    #[arg(long)]
48    pub path: String,
49    /// Free-text note describing the favorite.
50    #[arg(long)]
51    pub note: String,
52}
53
54#[derive(clap::Args)]
55#[command(args_conflicts_with_subcommands = true)]
56pub struct Command {
57    #[command(flatten)]
58    pub args: Args,
59    #[command(subcommand)]
60    pub schema: Option<Schema>,
61}
62
63#[derive(clap::Subcommand)]
64pub enum Schema {
65    /// Emit the JSON Schema for this leaf's `Request` type and exit.
66    RequestSchema(request_schema::Args),
67    /// Emit the JSON Schema for this leaf's `Response` type and exit.
68    ResponseSchema(response_schema::Args),
69}
70
71impl TryFrom<Args> for Request {
72    type Error = crate::cli::command::FromArgsError;
73    fn try_from(args: Args) -> Result<Self, Self::Error> {
74        let path = args
75            .path
76            .parse::<RemotePathCommitOptional>()
77            .map_err(|msg| crate::cli::command::FromArgsError::path_parse("path", msg))?;
78        Ok(Self {
79            path_type: Path::ConfigSwarmsFavoritesAdd,
80            name: args.name,
81            path,
82            note: args.note,
83        })
84    }
85}
86
87#[cfg(feature = "cli-executor")]
88pub async fn execute<E: crate::cli::command::CommandExecutor>(
89    executor: &E,
90    request: Request,
91
92        agent_arguments: Option<&crate::cli::command::AgentArguments>,
93    ) -> Result<Response, E::Error> {
94    executor.execute_one(request, agent_arguments).await
95}
96
97pub mod request_schema;
98
99
100pub mod response_schema;
101
102#[cfg(feature = "cli-executor")]
103pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
104    executor: &E,
105    request: Request,
106    _jq: String,
107
108        agent_arguments: Option<&crate::cli::command::AgentArguments>,
109    ) -> Result<serde_json::Value, E::Error> {
110    let resp: Response = executor.execute_one(request, agent_arguments).await?;
111    Ok(serde_json::to_value(resp).expect("Response serializes"))
112}