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