cli: Improve `rad node` output
This commit is contained in:
parent
df0b5da559
commit
0c43b05066
|
|
@ -73,7 +73,7 @@ issue the `rad node stop` command:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rad node stop
|
$ rad node stop
|
||||||
✓ Stopping node...
|
✓ Node stopped
|
||||||
```
|
```
|
||||||
|
|
||||||
Running the command again gives us an error:
|
Running the command again gives us an error:
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub const HELP: Help = Help {
|
||||||
Usage
|
Usage
|
||||||
|
|
||||||
rad node status [<option>...]
|
rad node status [<option>...]
|
||||||
rad node start [--foreground] [<option>...] [-- <node-option>...]
|
rad node start [--foreground] [--verbose] [<option>...] [-- <node-option>...]
|
||||||
rad node stop [<option>...]
|
rad node stop [<option>...]
|
||||||
rad node logs [-n <lines>]
|
rad node logs [-n <lines>]
|
||||||
rad node connect <nid>@<addr> [<option>...]
|
rad node connect <nid>@<addr> [<option>...]
|
||||||
|
|
@ -40,6 +40,7 @@ Usage
|
||||||
Start options
|
Start options
|
||||||
|
|
||||||
--foreground Start the node in the foreground
|
--foreground Start the node in the foreground
|
||||||
|
--verbose, -v Verbose output
|
||||||
|
|
||||||
Routing options
|
Routing options
|
||||||
|
|
||||||
|
|
@ -83,6 +84,7 @@ pub enum Operation {
|
||||||
},
|
},
|
||||||
Start {
|
Start {
|
||||||
foreground: bool,
|
foreground: bool,
|
||||||
|
verbose: bool,
|
||||||
options: Vec<OsString>,
|
options: Vec<OsString>,
|
||||||
},
|
},
|
||||||
Logs {
|
Logs {
|
||||||
|
|
@ -133,6 +135,7 @@ impl Args for Options {
|
||||||
let mut lines: usize = 10;
|
let mut lines: usize = 10;
|
||||||
let mut count: usize = usize::MAX;
|
let mut count: usize = usize::MAX;
|
||||||
let mut timeout = time::Duration::MAX;
|
let mut timeout = time::Duration::MAX;
|
||||||
|
let mut verbose = false;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
match arg {
|
match arg {
|
||||||
|
|
@ -183,6 +186,9 @@ impl Args for Options {
|
||||||
Long("foreground") if matches!(op, Some(OperationName::Start)) => {
|
Long("foreground") if matches!(op, Some(OperationName::Start)) => {
|
||||||
foreground = true;
|
foreground = true;
|
||||||
}
|
}
|
||||||
|
Long("verbose") | Short('v') if matches!(op, Some(OperationName::Start)) => {
|
||||||
|
verbose = true;
|
||||||
|
}
|
||||||
Short('n') if matches!(op, Some(OperationName::Logs)) => {
|
Short('n') if matches!(op, Some(OperationName::Logs)) => {
|
||||||
lines = parser.value()?.parse()?;
|
lines = parser.value()?.parse()?;
|
||||||
}
|
}
|
||||||
|
|
@ -205,6 +211,7 @@ impl Args for Options {
|
||||||
OperationName::Logs => Operation::Logs { lines },
|
OperationName::Logs => Operation::Logs { lines },
|
||||||
OperationName::Start => Operation::Start {
|
OperationName::Start => Operation::Start {
|
||||||
foreground,
|
foreground,
|
||||||
|
verbose,
|
||||||
options,
|
options,
|
||||||
},
|
},
|
||||||
OperationName::Status => Operation::Status,
|
OperationName::Status => Operation::Status,
|
||||||
|
|
@ -244,8 +251,9 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
Operation::Start {
|
Operation::Start {
|
||||||
foreground,
|
foreground,
|
||||||
options,
|
options,
|
||||||
|
verbose,
|
||||||
} => {
|
} => {
|
||||||
control::start(node, !foreground, options, &profile)?;
|
control::start(node, !foreground, verbose, options, &profile)?;
|
||||||
}
|
}
|
||||||
Operation::Status => {
|
Operation::Status => {
|
||||||
control::status(&node, &profile)?;
|
control::status(&node, &profile)?;
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,13 @@ use radicle::{profile, Profile};
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
use crate::terminal::Element as _;
|
use crate::terminal::Element as _;
|
||||||
|
|
||||||
|
/// How long to wait for the node to start before returning an error.
|
||||||
|
pub const NODE_START_TIMEOUT: time::Duration = time::Duration::from_secs(6);
|
||||||
|
|
||||||
pub fn start(
|
pub fn start(
|
||||||
node: Node,
|
node: Node,
|
||||||
daemon: bool,
|
daemon: bool,
|
||||||
|
verbose: bool,
|
||||||
mut options: Vec<OsString>,
|
mut options: Vec<OsString>,
|
||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
|
@ -54,7 +58,30 @@ pub fn start(
|
||||||
.stderr(process::Stdio::null())
|
.stderr(process::Stdio::null())
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
|
||||||
|
if verbose {
|
||||||
logs(0, Some(time::Duration::from_secs(1)), profile)?;
|
logs(0, Some(time::Duration::from_secs(1)), profile)?;
|
||||||
|
} else {
|
||||||
|
let started = time::Instant::now();
|
||||||
|
loop {
|
||||||
|
if node.is_running() {
|
||||||
|
term::success!("Node started");
|
||||||
|
term::print(term::format::dim(
|
||||||
|
"To stay in sync with the network, leave the node running in the background.",
|
||||||
|
));
|
||||||
|
term::info!(
|
||||||
|
"{} {}{}",
|
||||||
|
term::format::dim("To learn more, run"),
|
||||||
|
term::format::command("rad node --help"),
|
||||||
|
term::format::dim("."),
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
} else if started.elapsed() >= NODE_START_TIMEOUT {
|
||||||
|
anyhow::bail!("node failed to start. Try running in verbose mode with `rad node start --verbose`");
|
||||||
|
}
|
||||||
|
thread::sleep(time::Duration::from_millis(60));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut child = process::Command::new("radicle-node")
|
let mut child = process::Command::new("radicle-node")
|
||||||
.args(options)
|
.args(options)
|
||||||
|
|
@ -68,10 +95,11 @@ pub fn start(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(node: Node) -> anyhow::Result<()> {
|
pub fn stop(node: Node) -> anyhow::Result<()> {
|
||||||
let spinner = term::spinner("Stopping node...");
|
let mut spinner = term::spinner("Stopping node...");
|
||||||
if node.shutdown().is_err() {
|
if node.shutdown().is_err() {
|
||||||
spinner.error("node is not running");
|
spinner.error("node is not running");
|
||||||
} else {
|
} else {
|
||||||
|
spinner.message("Node stopped");
|
||||||
spinner.finish();
|
spinner.finish();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue