cli: Start node in background by default

It makes much more sense to start the node in the background, now that
we have commands to interact with it.
This commit is contained in:
Alexis Sellier 2023-07-15 19:25:00 +02:00
parent edd70b701e
commit 18dacbb48c
No known key found for this signature in database
1 changed files with 18 additions and 8 deletions

View File

@ -26,7 +26,7 @@ pub const HELP: Help = Help {
Usage Usage
rad node status [<option>...] rad node status [<option>...]
rad node start [--daemon | -d] [<option>...] [-- <node-option>...] rad node start [--foreground] [<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>...]
@ -36,6 +36,10 @@ Usage
For `<node-option>` see `radicle-node --help`. For `<node-option>` see `radicle-node --help`.
Start options
--foreground Start the node in the foreground
Routing options Routing options
--rid <rid> Show the routing table entries for the given RID --rid <rid> Show the routing table entries for the given RID
@ -68,7 +72,7 @@ pub enum Operation {
nid: Option<NodeId>, nid: Option<NodeId>,
}, },
Start { Start {
daemon: bool, foreground: bool,
options: Vec<OsString>, options: Vec<OsString>,
}, },
Logs { Logs {
@ -105,7 +109,7 @@ impl Args for Options {
fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> { fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
use lexopt::prelude::*; use lexopt::prelude::*;
let mut daemon = false; let mut foreground = false;
let mut options = vec![]; let mut options = vec![];
let mut parser = lexopt::Parser::from_args(args); let mut parser = lexopt::Parser::from_args(args);
let mut op: Option<OperationName> = None; let mut op: Option<OperationName> = None;
@ -151,8 +155,8 @@ impl Args for Options {
Long("nodes") if matches!(op, Some(OperationName::Tracking)) => { Long("nodes") if matches!(op, Some(OperationName::Tracking)) => {
tracking_mode = TrackingMode::Nodes tracking_mode = TrackingMode::Nodes
} }
Long("daemon") | Short('d') if matches!(op, Some(OperationName::Start)) => { Long("foreground") if matches!(op, Some(OperationName::Start)) => {
daemon = true; foreground = 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()?;
@ -173,7 +177,10 @@ impl Args for Options {
OperationName::Events => Operation::Events, OperationName::Events => Operation::Events,
OperationName::Routing => Operation::Routing { rid, nid, json }, OperationName::Routing => Operation::Routing { rid, nid, json },
OperationName::Logs => Operation::Logs { lines }, OperationName::Logs => Operation::Logs { lines },
OperationName::Start => Operation::Start { daemon, options }, OperationName::Start => Operation::Start {
foreground,
options,
},
OperationName::Status => Operation::Status, OperationName::Status => Operation::Status,
OperationName::Stop => Operation::Stop, OperationName::Stop => Operation::Stop,
OperationName::Tracking => Operation::Tracking { OperationName::Tracking => Operation::Tracking {
@ -199,8 +206,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
routing::run(&store, rid, nid, json)?; routing::run(&store, rid, nid, json)?;
} }
Operation::Logs { lines } => control::logs(lines, Some(time::Duration::MAX), &profile)?, Operation::Logs { lines } => control::logs(lines, Some(time::Duration::MAX), &profile)?,
Operation::Start { daemon, options } => { Operation::Start {
control::start(node, daemon, options, &profile)?; foreground,
options,
} => {
control::start(node, !foreground, options, &profile)?;
} }
Operation::Status => { Operation::Status => {
control::status(&node, &profile)?; control::status(&node, &profile)?;