feat(rust): support stdin in command message send
use clap::Args;
+use std::io;
+use std::str::FromStr;
use ockam::{Context, TcpTransport};
use ockam_multiaddr::MultiAddr;
@@ -7,7 +9,7 @@ use crate::util::embedded_node;
#[derive(Clone, Debug, Args)]
pub struct SendCommand {
- addr: MultiAddr,
+ addr: String,
message: String,
}
@@ -20,7 +22,22 @@ impl SendCommand {
async fn send_message(mut ctx: Context, cmd: SendCommand) -> anyhow::Result<()> {
let _tcp = TcpTransport::create(&ctx).await?;
- if let Some(route) = ockam_api::multiaddr_to_route(&cmd.addr) {
+ let addr = match cmd.addr {
+ addr if addr.contains("/-") => {
+ let mut buffer = String::new();
+ io::stdin().read_line(&mut buffer)?;
+ addr.replace("/-", &buffer.trim())
+ }
+ addr if addr.contains("-/") => {
+ let mut buffer = String::new();
+ io::stdin().read_line(&mut buffer)?;
+ addr.replace("-/", &buffer.trim())
+ }
+ _ => cmd.addr,
+ };
+
+ let addr = MultiAddr::from_str(&addr)?;
+ if let Some(route) = ockam_api::multiaddr_to_route(&addr) {
ctx.send(route, cmd.message).await?;
let message = ctx.receive::<String>().await?;
println!("{}", message);
