-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcli.rs
46 lines (42 loc) · 1.14 KB
/
cli.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use anyhow::Result;
use browser_echo::node::EchoNode;
use clap::Parser;
use iroh::NodeId;
use n0_future::StreamExt;
#[derive(Debug, Parser)]
struct Args {
#[clap(subcommand)]
command: Command,
}
#[derive(Debug, Parser)]
enum Command {
Connect { node_id: NodeId, payload: String },
Accept,
}
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let args = Args::parse();
let node = EchoNode::spawn().await?;
match args.command {
Command::Connect { node_id, payload } => {
let mut events = node.connect(node_id, payload);
while let Some(event) = events.next().await {
println!("event {event:?}");
}
}
Command::Accept => {
println!("connect to this node:");
println!(
"cargo run -- connect {} {}",
node.endpoint().node_id(),
"hello-please-echo-back"
);
let mut events = node.accept_events();
while let Some(event) = events.next().await {
println!("event {event:?}");
}
}
}
Ok(())
}