objectiveai_sdk/cli/command/api/config/mcp_authorization/add/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.api.config.mcp_authorization.add.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 key: String,
13 pub value: String,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
17#[schemars(rename = "cli.command.api.config.mcp_authorization.add.Path")]
18pub enum Path {
19 #[serde(rename = "api/config/mcp_authorization/add")]
20 ApiConfigMcpAuthorizationAdd,
21}
22
23impl CommandRequest for Request {
24 fn request_base(&self) -> &crate::cli::command::RequestBase {
25 &self.base
26 }
27
28 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
29 Some(&mut self.base)
30 }
31}
32
33pub type Response = crate::cli::command::Ok;
34
35#[derive(clap::Args)]
36#[command(group(clap::ArgGroup::new("key_required").required(true).args(["key"])))]
37#[command(group(clap::ArgGroup::new("value_required").required(true).args(["value"])))]
38pub struct Args {
39 #[arg(long)]
41 pub global: bool,
42 #[arg(long)]
44 pub state: bool,
45 #[command(flatten)]
46 pub base: crate::cli::command::RequestBaseArgs,
47 #[arg(long)]
49 pub key: Option<String>,
50 #[arg(long)]
52 pub value: Option<String>,
53}
54
55#[derive(clap::Args)]
56#[command(args_conflicts_with_subcommands = true)]
57pub struct Command {
58 #[command(flatten)]
59 pub args: Args,
60 #[command(subcommand)]
61 pub schema: Option<Schema>,
62}
63
64#[derive(clap::Subcommand)]
65pub enum Schema {
66 RequestSchema(request_schema::Args),
68 ResponseSchema(response_schema::Args),
70}
71
72impl TryFrom<Args> for Request {
73 type Error = crate::cli::command::FromArgsError;
74 fn try_from(args: Args) -> Result<Self, Self::Error> {
75 let scope = match (args.global, args.state) {
76 (true, false) => crate::cli::command::SetScope::Global,
77 (false, true) => crate::cli::command::SetScope::State,
78 _ => {
79 return Err(crate::cli::command::FromArgsError {
80 field: "scope",
81 source: crate::cli::command::FromArgsErrorSource::Plain(
82 "exactly one of --global, --state is required".to_string(),
83 ),
84 });
85 }
86 };
87 Ok(Self {
88 base: args.base.into(), path_type: Path::ApiConfigMcpAuthorizationAdd,
89 scope,
90 key: args.key.ok_or_else(|| {
91 crate::cli::command::FromArgsError::path_parse(
92 "key",
93 "--key is required".to_string(),
94 )
95 })?,
96 value: args.value.ok_or_else(|| {
97 crate::cli::command::FromArgsError::path_parse(
98 "value",
99 "--value is required".to_string(),
100 )
101 })?,
102 })
103 }
104}
105
106#[cfg(feature = "cli-executor")]
107pub async fn execute<E: crate::cli::command::CommandExecutor>(
108 executor: &E,
109 request: Request,
110
111 agent_arguments: Option<&crate::cli::command::AgentArguments>,
112 ) -> Result<Response, E::Error> {
113 executor.execute_one(request, agent_arguments).await
114}
115
116pub mod request_schema;
117
118
119pub mod response_schema;
120
121#[cfg(feature = "cli-executor")]
122pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
123 executor: &E,
124 request: Request,
125 _transform: crate::cli::command::Transform,
126
127 agent_arguments: Option<&crate::cli::command::AgentArguments>,
128 ) -> Result<serde_json::Value, E::Error> {
129 let resp: Response = executor.execute_one(request, agent_arguments).await?;
130 Ok(serde_json::to_value(resp).expect("Response serializes"))
131}