objectiveai_sdk/cli/command/daemon/config/set/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.daemon.config.set.Request")]
7pub struct Request {
8 pub path_type: Path,
9 #[serde(flatten)]
10 pub base: crate::cli::command::RequestBase,
11 pub value: Value,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
20#[schemars(rename = "cli.command.daemon.config.set.Value")]
21pub struct Value {
22 #[serde(default, skip_serializing_if = "Option::is_none")]
23 #[schemars(extend("omitempty" = true))]
24 pub address: Option<String>,
25 #[serde(default, skip_serializing_if = "Option::is_none")]
26 #[schemars(extend("omitempty" = true))]
27 pub secret: Option<String>,
28 #[serde(default, skip_serializing_if = "Option::is_none")]
29 #[schemars(extend("omitempty" = true))]
30 pub signature: Option<String>,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
34#[schemars(rename = "cli.command.daemon.config.set.Path")]
35pub enum Path {
36 #[serde(rename = "daemon/config/set")]
37 DaemonConfigSet,
38}
39
40impl CommandRequest for Request {
41 fn request_base(&self) -> &crate::cli::command::RequestBase {
42 &self.base
43 }
44
45 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
46 Some(&mut self.base)
47 }
48}
49
50pub type Response = crate::cli::command::Ok;
51
52#[derive(clap::Args)]
53#[command(group(clap::ArgGroup::new("value_required").required(true).args(["value"])))]
54pub struct Args {
55 #[command(flatten)]
56 pub base: crate::cli::command::RequestBaseArgs,
57 #[arg(long)]
60 pub value: Option<String>,
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 raw = args.value.ok_or_else(|| {
84 crate::cli::command::FromArgsError::path_parse(
85 "value",
86 "--value is required".to_string(),
87 )
88 })?;
89 let mut de = serde_json::Deserializer::from_str(&raw);
90 let value = serde_path_to_error::deserialize(&mut de)
91 .map_err(|e| crate::cli::command::FromArgsError::json("value", e))?;
92 Ok(Self {
93 base: args.base.into(),
94 path_type: Path::DaemonConfigSet,
95 value,
96 })
97 }
98}
99
100#[cfg(feature = "cli-executor")]
101pub async fn execute<E: crate::cli::command::CommandExecutor>(
102 executor: &E,
103 request: Request,
104
105 agent_arguments: Option<&crate::cli::command::AgentArguments>,
106 ) -> Result<Response, E::Error> {
107 executor.execute_one(request, agent_arguments).await
108}
109
110pub mod request_schema;
111
112pub mod response_schema;
113
114#[cfg(feature = "cli-executor")]
115pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
116 executor: &E,
117 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 let resp: Response = executor.execute_one(request, agent_arguments).await?;
123 Ok(serde_json::to_value(resp).expect("Response serializes"))
124}
125
126#[cfg(feature = "cli-listener")]
131pub struct ListenerExecution {
132 pub request: Request,
133 pub agent_arguments: crate::cli::command::AgentArguments,
134 pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
135}