Skip to main content

objectiveai_sdk/cli/command/config/agents/favorites/edit/
mod.rs

1//! `config agents favorites edit` — 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.config.agents.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.agents.favorites.edit.Path")]
16pub enum Path {
17    #[serde(rename = "config/agents/favorites/edit")]
18    ConfigAgentsFavoritesEdit,
19}
20
21#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
22#[schemars(rename = "cli.command.config.agents.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![
33            "config".to_string(),
34            "agents".to_string(),
35            "favorites".to_string(),
36            "edit".to_string(),
37            self.name.clone(),
38        ];
39        if let Some(note) = &self.note {
40            argv.push("--note".to_string());
41            argv.push(note.clone());
42        }
43        match &self.commit {
44            Some(RequestCommitChange::Set(c)) => {
45                argv.push("--commit".to_string());
46                argv.push(c.clone());
47            }
48            Some(RequestCommitChange::Remove) => {
49                argv.push("--remove-commit".to_string());
50            }
51            None => {}
52        }
53        argv
54    }
55}
56
57pub type Response = crate::cli::command::Ok;
58
59#[derive(clap::Args)]
60pub struct Args {
61    /// Favorite name.
62    pub name: String,
63    /// New note (omit to leave unchanged).
64    #[arg(long)]
65    pub note: Option<String>,
66    /// Set the pinned commit SHA.
67    #[arg(long, conflicts_with = "remove_commit")]
68    pub commit: Option<String>,
69    /// Remove the pinned commit SHA.
70    #[arg(long, conflicts_with = "commit")]
71    pub remove_commit: bool,
72}
73
74#[derive(clap::Args)]
75#[command(args_conflicts_with_subcommands = true)]
76pub struct Command {
77    #[command(flatten)]
78    pub args: Args,
79    #[command(subcommand)]
80    pub schema: Option<Schema>,
81}
82
83#[derive(clap::Subcommand)]
84pub enum Schema {
85    /// Emit the JSON Schema for this leaf's `Request` type and exit.
86    RequestSchema(request_schema::Args),
87    /// Emit the JSON Schema for this leaf's `Response` type and exit.
88    ResponseSchema(response_schema::Args),
89}
90
91impl TryFrom<Args> for Request {
92    type Error = crate::cli::command::FromArgsError;
93    fn try_from(args: Args) -> Result<Self, Self::Error> {
94        let commit = if let Some(c) = args.commit {
95            Some(RequestCommitChange::Set(c))
96        } else if args.remove_commit {
97            Some(RequestCommitChange::Remove)
98        } else {
99            None
100        };
101        Ok(Self { path_type: Path::ConfigAgentsFavoritesEdit,
102            name: args.name,
103            note: args.note,
104            commit,
105        })
106    }
107}
108
109#[cfg(feature = "cli-executor")]
110pub async fn execute<E: crate::cli::command::CommandExecutor>(
111    executor: &E,
112    request: Request,
113
114        agent_arguments: Option<&crate::cli::command::AgentArguments>,
115    ) -> Result<Response, E::Error> {
116    executor.execute_one(request, agent_arguments).await
117}
118
119pub mod request_schema;
120
121
122pub mod response_schema;
123
124#[cfg(feature = "cli-executor")]
125pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
126    executor: &E,
127    request: Request,
128    _jq: String,
129
130        agent_arguments: Option<&crate::cli::command::AgentArguments>,
131    ) -> Result<serde_json::Value, E::Error> {
132    let resp: Response = executor.execute_one(request, agent_arguments).await?;
133    Ok(serde_json::to_value(resp).expect("Response serializes"))
134}