Skip to main content

objectiveai_sdk/cli/command/api/config/user_agent/set/
mod.rs

1//! `config api user-agent set` — 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.api.config.user_agent.set.Request")]
7pub struct Request {
8    pub path_type: Path,
9    #[serde(flatten)]
10    pub base: crate::cli::command::RequestBase,
11    pub scope: crate::cli::command::SetScope,
12    pub value: String,
13}
14
15#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
16#[schemars(rename = "cli.command.api.config.user_agent.set.Path")]
17pub enum Path {
18    #[serde(rename = "api/config/user_agent/set")]
19    ApiConfigUserAgentSet,
20}
21
22impl CommandRequest for Request {
23    fn into_command(&self) -> Vec<String> {
24        let mut argv = vec!["api".to_string(), "config".to_string(), "user-agent".to_string(), "set".to_string(), self.value.clone()];
25        argv.push(match self.scope {
26            crate::cli::command::SetScope::Global => "--global".to_string(),
27            crate::cli::command::SetScope::State => "--state".to_string(),
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
42pub type Response = crate::cli::command::Ok;
43
44#[derive(clap::Args)]
45pub struct Args {
46    /// Mutate the global config layer.
47    #[arg(long)]
48    pub global: bool,
49    /// Mutate the state config layer.
50    #[arg(long)]
51    pub state: bool,
52    #[command(flatten)]
53    pub base: crate::cli::command::RequestBaseArgs,
54    /// New value.
55    pub value: String,
56}
57
58#[derive(clap::Args)]
59#[command(args_conflicts_with_subcommands = true)]
60pub struct Command {
61    #[command(flatten)]
62    pub args: Args,
63    #[command(subcommand)]
64    pub schema: Option<Schema>,
65}
66
67#[derive(clap::Subcommand)]
68pub enum Schema {
69    /// Emit the JSON Schema for this leaf's `Request` type and exit.
70    RequestSchema(request_schema::Args),
71    /// Emit the JSON Schema for this leaf's `Response` type and exit.
72    ResponseSchema(response_schema::Args),
73}
74
75impl TryFrom<Args> for Request {
76    type Error = crate::cli::command::FromArgsError;
77    fn try_from(args: Args) -> Result<Self, Self::Error> {
78        let scope = match (args.global, args.state) {
79            (true, false) => crate::cli::command::SetScope::Global,
80            (false, true) => crate::cli::command::SetScope::State,
81            _ => {
82                return Err(crate::cli::command::FromArgsError {
83                    field: "scope",
84                    source: crate::cli::command::FromArgsErrorSource::Plain(
85                        "exactly one of --global, --state is required".to_string(),
86                    ),
87                });
88            }
89        };
90        Ok(Self {
91            base: args.base.into(), path_type: Path::ApiConfigUserAgentSet,
92            scope,
93            value: args.value,
94        })
95    }
96}
97
98#[cfg(feature = "cli-executor")]
99pub async fn execute<E: crate::cli::command::CommandExecutor>(
100    executor: &E,
101    request: Request,
102
103        agent_arguments: Option<&crate::cli::command::AgentArguments>,
104    ) -> Result<Response, E::Error> {
105    executor.execute_one(request, agent_arguments).await
106}
107
108pub mod request_schema;
109
110
111pub mod response_schema;
112
113#[cfg(feature = "cli-executor")]
114pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
115    executor: &E,
116    request: Request,
117    _transform: crate::cli::command::Transform,
118
119        agent_arguments: Option<&crate::cli::command::AgentArguments>,
120    ) -> Result<serde_json::Value, E::Error> {
121    let resp: Response = executor.execute_one(request, agent_arguments).await?;
122    Ok(serde_json::to_value(resp).expect("Response serializes"))
123}