cli: Show logs in `rad node status`
This commit is contained in:
parent
e32e28f8b4
commit
2e6c9827a9
|
|
@ -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))?;
|
radicle::node::routing::Table::reader(profile.home.node().join(ROUTING_DB_FILE))?;
|
||||||
routing::run(&store, rid, nid, json)?;
|
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::Start { daemon, options } => control::start(daemon, options)?,
|
||||||
Operation::Status => {
|
Operation::Status => {
|
||||||
let node = Node::new(profile.socket());
|
let node = Node::new(profile.socket());
|
||||||
control::status(&node);
|
control::status(&node)?;
|
||||||
}
|
}
|
||||||
Operation::Stop => {
|
Operation::Stop => {
|
||||||
let node = Node::new(profile.socket());
|
let node = Node::new(profile.socket());
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ pub fn stop(node: Node) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn logs(lines: usize) -> anyhow::Result<()> {
|
pub fn logs(lines: usize, follow: bool) -> anyhow::Result<()> {
|
||||||
let home = radicle::profile::home()?;
|
let home = radicle::profile::home()?;
|
||||||
let logs = home.node().join("node.log");
|
let logs = home.node().join("node.log");
|
||||||
|
|
||||||
|
|
@ -80,16 +80,19 @@ pub fn logs(lines: usize) -> anyhow::Result<()> {
|
||||||
|
|
||||||
print!("{}", String::from_utf8_lossy(&tail));
|
print!("{}", String::from_utf8_lossy(&tail));
|
||||||
|
|
||||||
file.seek(SeekFrom::End(0))?;
|
if follow {
|
||||||
loop {
|
file.seek(SeekFrom::End(0))?;
|
||||||
let mut line = String::new();
|
loop {
|
||||||
let len = file.read_line(&mut line)?;
|
let mut line = String::new();
|
||||||
if len == 0 {
|
let len = file.read_line(&mut line)?;
|
||||||
thread::sleep(Duration::from_millis(250));
|
if len == 0 {
|
||||||
} else {
|
thread::sleep(Duration::from_millis(250));
|
||||||
print!("{line}");
|
} else {
|
||||||
|
print!("{line}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect(node: &mut Node, nid: NodeId, addr: Address) -> anyhow::Result<()> {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn status(node: &Node) {
|
pub fn status(node: &Node) -> anyhow::Result<()> {
|
||||||
if node.is_running() {
|
if node.is_running() {
|
||||||
term::success!("The node is {}", term::format::positive("running"));
|
term::success!("The node is {}", term::format::positive("running"));
|
||||||
} else {
|
} else {
|
||||||
term::info!("The node is {}", term::format::negative("stopped"));
|
term::info!("The node is {}", term::format::negative("stopped"));
|
||||||
}
|
}
|
||||||
|
term::blank();
|
||||||
|
|
||||||
|
logs(10, false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue