Skip to main content

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

1//! `config functions 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.functions.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.functions.favorites.edit.Path")]
16pub enum Path {
17    #[serde(rename = "config/functions/favorites/edit")]
18    ConfigFunctionsFavoritesEdit,
19}
20
21#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
22#[schemars(rename = "cli.command.config.functions.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(), "functions".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    /// Favorite name.
56    pub name: String,
57    /// New note (omit to leave unchanged).
58    #[arg(long)]
59    pub note: Option<String>,
60    /// Set the pinned commit SHA.
61    #[arg(long, conflicts_with = "remove_commit")]
62    pub commit: Option<String>,
63    /// Remove the pinned commit SHA.
64    #[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    /// Emit the JSON Schema for this leaf's `Request` type and exit.
80    RequestSchema(request_schema::Args),
81    /// Emit the JSON Schema for this leaf's `Response` type and exit.
82    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::ConfigFunctionsFavoritesEdit,
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}