use crate::cli::command::CommandRequest;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.daemon.config.set.Request")]
pub struct Request {
pub path_type: Path,
#[serde(flatten)]
pub base: crate::cli::command::RequestBase,
pub value: Value,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.daemon.config.set.Value")]
pub struct Value {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(extend("omitempty" = true))]
pub address: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(extend("omitempty" = true))]
pub secret: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(extend("omitempty" = true))]
pub signature: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.daemon.config.set.Path")]
pub enum Path {
#[serde(rename = "daemon/config/set")]
DaemonConfigSet,
}
impl CommandRequest for Request {
fn request_base(&self) -> &crate::cli::command::RequestBase {
&self.base
}
fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
Some(&mut self.base)
}
}
pub type Response = crate::cli::command::Ok;
#[derive(clap::Args)]
#[command(group(clap::ArgGroup::new("value_required").required(true).args(["value"])))]
pub struct Args {
#[command(flatten)]
pub base: crate::cli::command::RequestBaseArgs,
#[arg(long)]
pub value: Option<String>,
}
#[derive(clap::Args)]
#[command(args_conflicts_with_subcommands = true)]
pub struct Command {
#[command(flatten)]
pub args: Args,
#[command(subcommand)]
pub schema: Option<Schema>,
}
#[derive(clap::Subcommand)]
pub enum Schema {
RequestSchema(request_schema::Args),
ResponseSchema(response_schema::Args),
}
impl TryFrom<Args> for Request {
type Error = crate::cli::command::FromArgsError;
fn try_from(args: Args) -> Result<Self, Self::Error> {
let raw = args.value.ok_or_else(|| {
crate::cli::command::FromArgsError::path_parse(
"value",
"--value is required".to_string(),
)
})?;
let mut de = serde_json::Deserializer::from_str(&raw);
let value = serde_path_to_error::deserialize(&mut de)
.map_err(|e| crate::cli::command::FromArgsError::json("value", e))?;
Ok(Self {
base: args.base.into(),
path_type: Path::DaemonConfigSet,
value,
})
}
}
#[cfg(feature = "cli-executor")]
pub async fn execute<E: crate::cli::command::CommandExecutor>(
executor: &E,
request: Request,
agent_arguments: Option<&crate::cli::command::AgentArguments>,
) -> Result<Response, E::Error> {
executor.execute_one(request, agent_arguments).await
}
pub mod request_schema;
pub mod response_schema;
#[cfg(feature = "cli-executor")]
pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
executor: &E,
request: Request,
_transform: crate::cli::command::Transform,
agent_arguments: Option<&crate::cli::command::AgentArguments>,
) -> Result<serde_json::Value, E::Error> {
let resp: Response = executor.execute_one(request, agent_arguments).await?;
Ok(serde_json::to_value(resp).expect("Response serializes"))
}
#[cfg(feature = "cli-listener")]
pub struct ListenerExecution {
pub request: Request,
pub agent_arguments: crate::cli::command::AgentArguments,
pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
}