Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: add version command to node
✗ CI failure Daniel Norman committed 1 month ago
commit 7b31415d2bc2bb8b451797af3c396c4e7d360a17
parent edde15d9ea700a70de04558fafc0b55360e9f5d2
1 failed (1 total) View logs
6 files changed +33 -2
modified crates/radicle-cli/src/commands/node/control.rs
@@ -282,18 +282,21 @@ pub fn status(node: &Node, profile: &Profile) -> anyhow::Result<()> {
    } else {
        term::format::yellow(term::format::node_id_human(&nid)).bold()
    };
+
    let version = node.version().unwrap_or_else(|_| String::from("unknown"));

    if listen.is_empty() {
        term::success!(
-
            "Node is {} with Node ID {} and {} configured to listen for inbound connections.",
+
            "Node is {} ({}) with Node ID {} and {} configured to listen for inbound connections.",
            term::format::positive("running"),
+
            version,
            nid,
            term::Paint::new("not").italic()
        );
    } else {
        term::success!(
-
            "Node is {} with Node ID {} and listening for inbound connections on {}.",
+
            "Node is {} ({}) with Node ID {} and listening for inbound connections on {}.",
            term::format::positive("running"),
+
            version,
            nid,
            listen.join(", ")
        );
modified crates/radicle-node/src/control.rs
@@ -246,6 +246,10 @@ where

            CommandResult::Okay(debug).to_writer(writer)?;
        }
+
        Command::Version => {
+
            let version = handle.version()?;
+
            CommandResult::Okay(version).to_writer(writer)?;
+
        }
        Command::Shutdown => {
            log::debug!(target: "control", "Shutdown requested..");
            // Channel might already be disconnected if shutdown
@@ -365,5 +369,7 @@ mod tests {
        assert!(!handle.follow(peer, Some(Alias::new("alice"))).unwrap());
        assert!(handle.unfollow(peer).unwrap());
        assert!(!handle.unfollow(peer).unwrap());
+

+
        assert_eq!(handle.version().unwrap(), "0.0.0");
    }
}
modified crates/radicle-node/src/runtime/handle.rs
@@ -361,6 +361,10 @@ impl radicle::node::Handle for Handle {
            .map_err(|_| Error::ChannelDisconnected)
    }

+
    fn version(&self) -> Result<String, Self::Error> {
+
        Ok(crate::VERSION.version.to_string())
+
    }
+

    fn debug(&self) -> Result<serde_json::Value, Self::Error> {
        let (sender, receiver) = chan::bounded(1);
        let query: Arc<QueryState> = Arc::new(move |state| {
modified crates/radicle-node/src/test/handle.rs
@@ -142,6 +142,10 @@ impl radicle::node::Handle for Handle {
        Ok(())
    }

+
    fn version(&self) -> Result<String, Self::Error> {
+
        Ok(String::from("0.0.0"))
+
    }
+

    fn debug(&self) -> Result<serde_json::Value, Self::Error> {
        Ok(serde_json::Value::Null)
    }
modified crates/radicle/src/node.rs
@@ -1018,6 +1018,8 @@ pub trait Handle: Clone + Sync + Send {
    fn subscribe(&self, timeout: time::Duration) -> Result<Self::Events, Self::Error>;
    /// Return debug information as a JSON value.
    fn debug(&self) -> Result<json::Value, Self::Error>;
+
    /// Get the node's version string.
+
    fn version(&self) -> Result<String, Self::Error>;
}

/// Iterator of results `T` when passing a [`Command`] to [`Node::call`].
@@ -1362,6 +1364,15 @@ impl Handle for Node {
        Ok(debug)
    }

+
    fn version(&self) -> Result<String, Self::Error> {
+
        let version = self
+
            .call::<String>(Command::Version, DEFAULT_TIMEOUT)?
+
            .next()
+
            .ok_or(Error::EmptyResponse)??;
+

+
        Ok(version)
+
    }
+

    fn shutdown(self) -> Result<(), Error> {
        for line in self.call::<Success>(Command::Shutdown, DEFAULT_TIMEOUT)? {
            line?;
modified crates/radicle/src/node/command.rs
@@ -135,6 +135,9 @@ pub enum Command {
    /// Get the node's NID.
    NodeId,

+
    /// Get the node's version.
+
    Version,
+

    /// Shutdown the node.
    Shutdown,