objectiveai_sdk/cli/command/config/swarms/favorites/edit/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.config.swarms.favorites.edit.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub name: String,
10 pub note: Option<String>,
11 pub commit: Option<RequestCommitChange>,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.config.swarms.favorites.edit.Path")]
16pub enum Path {
17 #[serde(rename = "config/swarms/favorites/edit")]
18 ConfigSwarmsFavoritesEdit,
19}
20
21#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
22#[schemars(rename = "cli.command.config.swarms.favorites.edit.RequestCommitChange")]
23pub enum RequestCommitChange {
24 #[schemars(title = "Set")]
25 Set(String),
26 #[schemars(title = "Remove")]
27 Remove,
28}
29
30impl CommandRequest for Request {
31 fn into_command(&self) -> Vec<String> {
32 let mut argv = vec!["config".to_string(), "swarms".to_string(), "favorites".to_string(), "edit".to_string(), self.name.clone()];
33 if let Some(note) = &self.note {
34 argv.push("--note".to_string());
35 argv.push(note.clone());
36 }
37 match &self.commit {
38 Some(RequestCommitChange::Set(c)) => {
39 argv.push("--commit".to_string());
40 argv.push(c.clone());
41 }
42 Some(RequestCommitChange::Remove) => {
43 argv.push("--remove-commit".to_string());
44 }
45 None => {}
46 }
47 argv
48 }
49}
50
51pub type Response = crate::cli::command::Ok;
52
53#[derive(clap::Args)]
54pub struct Args {
55 pub name: String,
57 #[arg(long)]
59 pub note: Option<String>,
60 #[arg(long, conflicts_with = "remove_commit")]
62 pub commit: Option<String>,
63 #[arg(long, conflicts_with = "commit")]
65 pub remove_commit: bool,
66}
67
68#[derive(clap::Args)]
69#[command(args_conflicts_with_subcommands = true)]
70pub struct Command {
71 #[command(flatten)]
72 pub args: Args,
73 #[command(subcommand)]
74 pub schema: Option<Schema>,
75}
76
77#[derive(clap::Subcommand)]
78pub enum Schema {
79 RequestSchema(request_schema::Args),
81 ResponseSchema(response_schema::Args),
83}
84
85impl TryFrom<Args> for Request {
86 type Error = crate::cli::command::FromArgsError;
87 fn try_from(args: Args) -> Result<Self, Self::Error> {
88 let commit = if let Some(c) = args.commit {
89 Some(RequestCommitChange::Set(c))
90 } else if args.remove_commit {
91 Some(RequestCommitChange::Remove)
92 } else {
93 None
94 };
95 Ok(Self { path_type: Path::ConfigSwarmsFavoritesEdit,
96 name: args.name,
97 note: args.note,
98 commit,
99 })
100 }
101}
102
103#[cfg(feature = "cli-executor")]
104pub async fn execute<E: crate::cli::command::CommandExecutor>(
105 executor: &E,
106 request: Request,
107
108 agent_arguments: Option<&crate::cli::command::AgentArguments>,
109 ) -> Result<Response, E::Error> {
110 executor.execute_one(request, agent_arguments).await
111}
112
113pub mod request_schema;
114
115
116pub mod response_schema;
117
118#[cfg(feature = "cli-executor")]
119pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
120 executor: &E,
121 request: Request,
122 _jq: String,
123
124 agent_arguments: Option<&crate::cli::command::AgentArguments>,
125 ) -> Result<serde_json::Value, E::Error> {
126 let resp: Response = executor.execute_one(request, agent_arguments).await?;
127 Ok(serde_json::to_value(resp).expect("Response serializes"))
128}