objectiveai_sdk/cli/command/api/config/get/
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.get.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub scope: crate::cli::command::GetScope,
10 #[serde(flatten)]
11 pub base: crate::cli::command::RequestBase,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.api.config.get.Path")]
16pub enum Path {
17 #[serde(rename = "api/config/get")]
18 ApiConfigGet,
19}
20
21impl CommandRequest for Request {
22 fn request_base(&self) -> &crate::cli::command::RequestBase {
23 &self.base
24 }
25
26 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
27 Some(&mut self.base)
28 }
29}
30
31#[derive(PartialEq, Debug, Clone, Default, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
32#[schemars(rename = "cli.command.api.config.get.Response")]
33pub struct Response {
34 #[serde(skip_serializing_if = "Option::is_none")]
35 #[schemars(extend("omitempty" = true))]
36 pub address: Option<String>,
37 #[serde(skip_serializing_if = "Option::is_none")]
38 #[schemars(extend("omitempty" = true))]
39 pub objectiveai_authorization: Option<String>,
40 #[serde(skip_serializing_if = "Option::is_none")]
41 #[schemars(extend("omitempty" = true))]
42 pub openrouter_authorization: Option<String>,
43 #[serde(skip_serializing_if = "Option::is_none")]
44 #[schemars(extend("omitempty" = true))]
45 pub github_authorization: Option<String>,
46 #[serde(skip_serializing_if = "Option::is_none")]
47 #[schemars(extend("omitempty" = true))]
48 pub mcp_authorization: Option<indexmap::IndexMap<String, String>>,
49 #[serde(skip_serializing_if = "Option::is_none")]
50 #[schemars(extend("omitempty" = true))]
51 pub user_agent: Option<String>,
52 #[serde(skip_serializing_if = "Option::is_none")]
53 #[schemars(extend("omitempty" = true))]
54 pub http_referer: Option<String>,
55 #[serde(skip_serializing_if = "Option::is_none")]
56 #[schemars(extend("omitempty" = true))]
57 pub x_title: Option<String>,
58 #[serde(skip_serializing_if = "Option::is_none")]
59 #[schemars(extend("omitempty" = true))]
60 pub commit_author_name: Option<String>,
61 #[serde(skip_serializing_if = "Option::is_none")]
62 #[schemars(extend("omitempty" = true))]
63 pub commit_author_email: Option<String>,
64}
65
66#[derive(clap::Args)]
67pub struct Args {
68 #[arg(long)]
70 pub global: bool,
71 #[arg(long)]
73 pub state: bool,
74 #[arg(long)]
76 pub r#final: bool,
77 #[command(flatten)]
78 pub base: crate::cli::command::RequestBaseArgs,
79}
80
81#[derive(clap::Args)]
82#[command(args_conflicts_with_subcommands = true)]
83pub struct Command {
84 #[command(flatten)]
85 pub args: Args,
86 #[command(subcommand)]
87 pub schema: Option<Schema>,
88}
89
90#[derive(clap::Subcommand)]
91pub enum Schema {
92 RequestSchema(request_schema::Args),
94 ResponseSchema(response_schema::Args),
96}
97
98impl TryFrom<Args> for Request {
99 type Error = crate::cli::command::FromArgsError;
100 fn try_from(args: Args) -> Result<Self, Self::Error> {
101 let scope = match (args.global, args.state, args.r#final) {
102 (true, false, false) => crate::cli::command::GetScope::Global,
103 (false, true, false) => crate::cli::command::GetScope::State,
104 (false, false, true) => crate::cli::command::GetScope::Final,
105 _ => {
106 return Err(crate::cli::command::FromArgsError {
107 field: "scope",
108 source: crate::cli::command::FromArgsErrorSource::Plain(
109 "exactly one of --global, --state, --final is required".to_string(),
110 ),
111 });
112 }
113 };
114 Ok(Self { path_type: Path::ApiConfigGet,
115 scope,
116 base: args.base.into(),
117 })
118 }
119}
120
121#[cfg(feature = "cli-executor")]
122pub async fn execute<E: crate::cli::command::CommandExecutor>(
123 executor: &E,
124 mut request: Request,
125
126 agent_arguments: Option<&crate::cli::command::AgentArguments>,
127 ) -> Result<Response, E::Error> {
128 request.base.clear_transform();
129 executor.execute_one(request, agent_arguments).await
130}
131
132#[cfg(feature = "cli-executor")]
133pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
134 executor: &E,
135 mut request: Request,
136 transform: crate::cli::command::Transform,
137
138 agent_arguments: Option<&crate::cli::command::AgentArguments>,
139 ) -> Result<serde_json::Value, E::Error> {
140 request.base.set_transform(transform);
141 executor.execute_one(request, agent_arguments).await
142}
143
144#[cfg(feature = "mcp")]
145impl crate::cli::command::CommandResponse for Response {
146 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
147 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
148 }
149}
150
151pub mod request_schema;
152
153
154pub mod response_schema;