From 9ef7d27daa12e01f4472eef2bf3d5c405d624d70 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Thu, 20 Jun 2024 17:55:27 +0800 Subject: [PATCH] .. --- yazi-cli/src/args.rs | 31 ------------------------------- yazi-cli/src/main.rs | 9 +-------- yazi-dds/src/client.rs | 5 ++--- 3 files changed, 3 insertions(+), 42 deletions(-) diff --git a/yazi-cli/src/args.rs b/yazi-cli/src/args.rs index 16e084be..22ed257b 100644 --- a/yazi-cli/src/args.rs +++ b/yazi-cli/src/args.rs @@ -18,8 +18,6 @@ pub(super) struct Args { pub(super) enum Command { /// Publish a message to remote instance(s). Pub(CommandPub), - /// Publish a static message to all remote instances. - PubStatic(CommandPubStatic), /// Manage packages. Pack(CommandPack), /// Subscribe to messages from all remote instances. @@ -66,35 +64,6 @@ impl CommandPub { } } -#[derive(clap::Args)] -pub(super) struct CommandPubStatic { - /// The kind of message. - #[arg(index = 1)] - pub(super) kind: String, - /// The severity of the message. - #[arg(index = 2)] - pub(super) severity: u16, - /// Send the message with a string body. - #[arg(long)] - pub(super) str: Option, - /// Send the message with a JSON body. - #[arg(long)] - pub(super) json: Option, -} - -impl CommandPubStatic { - #[allow(dead_code)] - pub(super) fn body(&self) -> Result> { - if let Some(json) = &self.json { - Ok(json.into()) - } else if let Some(str) = &self.str { - Ok(serde_json::to_string(str)?.into()) - } else { - Ok("".into()) - } - } -} - #[derive(clap::Args)] #[command(arg_required_else_help = true)] pub(super) struct CommandPack { diff --git a/yazi-cli/src/main.rs b/yazi-cli/src/main.rs index 9fa6b84c..bfa09567 100644 --- a/yazi-cli/src/main.rs +++ b/yazi-cli/src/main.rs @@ -19,14 +19,7 @@ async fn main() -> anyhow::Result<()> { match Args::parse().command { Command::Pub(cmd) => { yazi_dds::init(); - if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver()?, None, &cmd.body()?).await { - eprintln!("Cannot send message: {e}"); - std::process::exit(1); - } - } - Command::PubStatic(cmd) => { - yazi_dds::init(); - if let Err(e) = yazi_dds::Client::shot(&cmd.kind, 0, Some(cmd.severity), &cmd.body()?).await { + if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver()?, &cmd.body()?).await { eprintln!("Cannot send message: {e}"); std::process::exit(1); } diff --git a/yazi-dds/src/client.rs b/yazi-dds/src/client.rs index ea79d6d1..0c29cd1c 100644 --- a/yazi-dds/src/client.rs +++ b/yazi-dds/src/client.rs @@ -64,12 +64,11 @@ impl Client { } /// Connect to an existing server to send a single message. - pub async fn shot(kind: &str, receiver: u64, severity: Option, body: &str) -> Result<()> { + pub async fn shot(kind: &str, receiver: u64, body: &str) -> Result<()> { Body::validate(kind)?; - let sender = severity.map(Into::into).unwrap_or(*ID); let payload = format!( - "{}\n{kind},{receiver},{sender},{body}\n{}\n", + "{}\n{kind},{receiver},{ID},{body}\n{}\n", Payload::new(BodyHi::borrowed(Default::default())), Payload::new(BodyBye::owned()) );