Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Show logs in `rad node status`
Alexis Sellier committed 2 years ago
commit 2e6c9827a91066b410a9404aa1c7f1ea7db798ab
parent e32e28f8b4ce082bf078106e4556741a9133d54c
2 files changed +18 -12
modified radicle-cli/src/commands/node.rs
@@ -210,11 +210,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
                radicle::node::routing::Table::reader(profile.home.node().join(ROUTING_DB_FILE))?;
            routing::run(&store, rid, nid, json)?;
        }
-
        Operation::Logs { lines } => control::logs(lines)?,
+
        Operation::Logs { lines } => control::logs(lines, true)?,
        Operation::Start { daemon, options } => control::start(daemon, options)?,
        Operation::Status => {
            let node = Node::new(profile.socket());
-
            control::status(&node);
+
            control::status(&node)?;
        }
        Operation::Stop => {
            let node = Node::new(profile.socket());
modified radicle-cli/src/commands/node/control.rs
@@ -53,7 +53,7 @@ pub fn stop(node: Node) -> anyhow::Result<()> {
    Ok(())
}

-
pub fn logs(lines: usize) -> anyhow::Result<()> {
+
pub fn logs(lines: usize, follow: bool) -> anyhow::Result<()> {
    let home = radicle::profile::home()?;
    let logs = home.node().join("node.log");

@@ -80,16 +80,19 @@ pub fn logs(lines: usize) -> anyhow::Result<()> {

    print!("{}", String::from_utf8_lossy(&tail));

-
    file.seek(SeekFrom::End(0))?;
-
    loop {
-
        let mut line = String::new();
-
        let len = file.read_line(&mut line)?;
-
        if len == 0 {
-
            thread::sleep(Duration::from_millis(250));
-
        } else {
-
            print!("{line}");
+
    if follow {
+
        file.seek(SeekFrom::End(0))?;
+
        loop {
+
            let mut line = String::new();
+
            let len = file.read_line(&mut line)?;
+
            if len == 0 {
+
                thread::sleep(Duration::from_millis(250));
+
            } else {
+
                print!("{line}");
+
            }
        }
    }
+
    Ok(())
}

pub fn connect(node: &mut Node, nid: NodeId, addr: Address) -> anyhow::Result<()> {
@@ -110,10 +113,13 @@ pub fn connect(node: &mut Node, nid: NodeId, addr: Address) -> anyhow::Result<()
    Ok(())
}

-
pub fn status(node: &Node) {
+
pub fn status(node: &Node) -> anyhow::Result<()> {
    if node.is_running() {
        term::success!("The node is {}", term::format::positive("running"));
    } else {
        term::info!("The node is {}", term::format::negative("stopped"));
    }
+
    term::blank();
+

+
    logs(10, false)
}