Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Add `rad node events` command
Sebastian Martinez committed 3 years ago
commit 8d8751655f1fbf990244d53fe0110731c68da07a
parent 90237e8e9d28d6b325a31a6a99339ae57a5ad777
2 files changed +25 -0
modified radicle-cli/src/commands/node.rs
@@ -9,6 +9,8 @@ use crate::terminal::args::{Args, Error, Help};

#[path = "node/control.rs"]
mod control;
+
#[path = "node/events.rs"]
+
mod events;
#[path = "node/routing.rs"]
mod routing;
#[path = "node/tracking.rs"]
@@ -21,6 +23,7 @@ pub const HELP: Help = Help {
    usage: r#"
Usage

+
    rad node events [<option>...]
    rad node status [<option>...]
    rad node start [--daemon|-d] [<option>...] [-- <node-option>...]
    rad node stop [<option>...]
@@ -47,6 +50,7 @@ pub enum Operation {
        nid: NodeId,
        addr: Address,
    },
+
    Events,
    Routing,
    Start {
        daemon: bool,
@@ -69,6 +73,7 @@ pub enum TrackingMode {
#[derive(Default)]
pub enum OperationName {
    Connect,
+
    Events,
    Routing,
    Start,
    #[default]
@@ -96,6 +101,7 @@ impl Args for Options {
                }
                Value(val) if op.is_none() => match val.to_string_lossy().as_ref() {
                    "connect" => op = Some(OperationName::Connect),
+
                    "events" => op = Some(OperationName::Events),
                    "routing" => op = Some(OperationName::Routing),
                    "start" => op = Some(OperationName::Start),
                    "status" => op = Some(OperationName::Status),
@@ -138,6 +144,7 @@ impl Args for Options {
                nid: nid.ok_or_else(|| anyhow!("an NID must be provided"))?,
                addr: addr.ok_or_else(|| anyhow!("an address must be provided"))?,
            },
+
            OperationName::Events => Operation::Events,
            OperationName::Routing => Operation::Routing,
            OperationName::Start => Operation::Start { daemon, options },
            OperationName::Status => Operation::Status,
@@ -158,6 +165,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
            let mut node = Node::new(profile.socket());
            control::connect(&mut node, nid, addr)?
        }
+
        Operation::Events => {
+
            let node = Node::new(profile.socket());
+
            events::run(node)?;
+
        }
        Operation::Routing => {
            let store =
                radicle::node::routing::Table::reader(profile.home.node().join(ROUTING_DB_FILE))?;
added radicle-cli/src/commands/node/events.rs
@@ -0,0 +1,14 @@
+
use std::time;
+

+
use radicle::node::Handle;
+

+
pub fn run(node: impl Handle) -> anyhow::Result<()> {
+
    let events = node.subscribe(time::Duration::MAX)?;
+
    for event in events {
+
        let event = event?;
+
        let json_string = serde_json::to_string(&event)?;
+
        println!("{json_string}");
+
    }
+

+
    Ok(())
+
}