mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
5816d81f1b
commit
9ef7d27daa
3 changed files with 3 additions and 42 deletions
|
|
@ -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<String>,
|
||||
/// Send the message with a JSON body.
|
||||
#[arg(long)]
|
||||
pub(super) json: Option<String>,
|
||||
}
|
||||
|
||||
impl CommandPubStatic {
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn body(&self) -> Result<Cow<str>> {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<u16>, 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())
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue