objectiveai_sdk/cli/command/db/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.db.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.db.config.get.Path")]
16pub enum Path {
17 #[serde(rename = "db/config/get")]
18 DbConfigGet,
19}
20
21impl CommandRequest for Request {
22 fn into_command(&self) -> Vec<String> {
23 let mut argv = vec!["db".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.db.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 user: Option<String>,
51 #[serde(skip_serializing_if = "Option::is_none")]
52 #[schemars(extend("omitempty" = true))]
53 pub password: Option<String>,
54 #[serde(skip_serializing_if = "Option::is_none")]
55 #[schemars(extend("omitempty" = true))]
56 pub database: Option<String>,
57}
58
59#[derive(clap::Args)]
60pub struct Args {
61 #[arg(long)]
63 pub global: bool,
64 #[arg(long)]
66 pub state: bool,
67 #[arg(long)]
69 pub r#final: bool,
70 #[command(flatten)]
71 pub base: crate::cli::command::RequestBaseArgs,
72}
73
74#[derive(clap::Args)]
75#[command(args_conflicts_with_subcommands = true)]
76pub struct Command {
77 #[command(flatten)]
78 pub args: Args,
79 #[command(subcommand)]
80 pub schema: Option<Schema>,
81}
82
83#[derive(clap::Subcommand)]
84pub enum Schema {
85 RequestSchema(request_schema::Args),
87 ResponseSchema(response_schema::Args),
89}
90
91impl TryFrom<Args> for Request {
92 type Error = crate::cli::command::FromArgsError;
93 fn try_from(args: Args) -> Result<Self, Self::Error> {
94 let scope = match (args.global, args.state, args.r#final) {
95 (true, false, false) => crate::cli::command::GetScope::Global,
96 (false, true, false) => crate::cli::command::GetScope::State,
97 (false, false, true) => crate::cli::command::GetScope::Final,
98 _ => {
99 return Err(crate::cli::command::FromArgsError {
100 field: "scope",
101 source: crate::cli::command::FromArgsErrorSource::Plain(
102 "exactly one of --global, --state, --final is required".to_string(),
103 ),
104 });
105 }
106 };
107 Ok(Self { path_type: Path::DbConfigGet,
108 scope,
109 base: args.base.into(),
110 })
111 }
112}
113
114#[cfg(feature = "cli-executor")]
115pub async fn execute<E: crate::cli::command::CommandExecutor>(
116 executor: &E,
117 mut request: Request,
118
119 agent_arguments: Option<&crate::cli::command::AgentArguments>,
120 ) -> Result<Response, E::Error> {
121 request.base.clear_transform();
122 executor.execute_one(request, agent_arguments).await
123}
124
125#[cfg(feature = "cli-executor")]
126pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
127 executor: &E,
128 mut request: Request,
129 transform: crate::cli::command::Transform,
130
131 agent_arguments: Option<&crate::cli::command::AgentArguments>,
132 ) -> Result<serde_json::Value, E::Error> {
133 request.base.set_transform(transform);
134 executor.execute_one(request, agent_arguments).await
135}
136
137#[cfg(feature = "mcp")]
138impl crate::cli::command::CommandResponse for Response {
139 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
140 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
141 }
142}
143
144pub mod request_schema;
145
146
147pub mod response_schema;