From b5b9a553060d6581c12bc368645a8f3f8ed6a23e Mon Sep 17 00:00:00 2001 From: cloudhead Date: Tue, 30 Jan 2024 15:57:05 +0100 Subject: [PATCH] cli: Add `--path` option to `rad node start` Useful for debugging and running nodes from different locations. --- radicle-cli/src/commands/node.rs | 12 +++++++++++- radicle-cli/src/commands/node/control.rs | 7 ++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/radicle-cli/src/commands/node.rs b/radicle-cli/src/commands/node.rs index f6948f20..341d3a0f 100644 --- a/radicle-cli/src/commands/node.rs +++ b/radicle-cli/src/commands/node.rs @@ -1,4 +1,5 @@ use std::ffi::OsString; +use std::path::PathBuf; use std::time; use anyhow::anyhow; @@ -38,6 +39,7 @@ Usage Start options --foreground Start the node in the foreground + --path Start node binary at path (default: radicle-node) --verbose, -v Verbose output Routing options @@ -79,6 +81,7 @@ pub enum Operation { Start { foreground: bool, verbose: bool, + path: PathBuf, options: Vec, }, Logs { @@ -118,6 +121,7 @@ impl Args for Options { let mut lines: usize = 60; let mut count: usize = usize::MAX; let mut timeout = time::Duration::MAX; + let mut path = None; let mut verbose = false; while let Some(arg) = parser.next()? { @@ -166,6 +170,10 @@ impl Args for Options { Long("verbose") | Short('v') if matches!(op, Some(OperationName::Start)) => { verbose = true; } + Long("path") if matches!(op, Some(OperationName::Start)) => { + let val = parser.value()?; + path = Some(PathBuf::from(val)); + } Short('n') if matches!(op, Some(OperationName::Logs)) => { lines = parser.value()?.parse()?; } @@ -191,6 +199,7 @@ impl Args for Options { foreground, verbose, options, + path: path.unwrap_or(PathBuf::from("radicle-node")), }, OperationName::Status => Operation::Status, OperationName::Sessions => Operation::Sessions, @@ -226,9 +235,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { Operation::Start { foreground, options, + path, verbose, } => { - control::start(node, !foreground, verbose, options, &profile)?; + control::start(node, !foreground, verbose, options, &path, &profile)?; } Operation::Status => { control::status(&node, &profile)?; diff --git a/radicle-cli/src/commands/node/control.rs b/radicle-cli/src/commands/node/control.rs index 0b8b7d05..ef6c9941 100644 --- a/radicle-cli/src/commands/node/control.rs +++ b/radicle-cli/src/commands/node/control.rs @@ -1,7 +1,7 @@ use std::ffi::OsString; use std::fs::{File, OpenOptions}; use std::io::{BufRead, BufReader, Read, Seek, SeekFrom}; -use std::{process, thread, time}; +use std::{path::Path, process, thread, time}; use localtime::LocalTime; @@ -21,6 +21,7 @@ pub fn start( daemon: bool, verbose: bool, mut options: Vec, + cmd: &Path, profile: &Profile, ) -> anyhow::Result<()> { if node.is_running() { @@ -54,7 +55,7 @@ pub fn start( .create(true) .open(profile.home.node().join("node.log"))?; - let child = process::Command::new("radicle-node") + let child = process::Command::new(cmd) .args(options) .envs(envs) .stdin(process::Stdio::null()) @@ -94,7 +95,7 @@ pub fn start( } } } else { - let mut child = process::Command::new("radicle-node") + let mut child = process::Command::new(cmd) .args(options) .envs(envs) .spawn()?;