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