cli: Add `--path` option to `rad node start`

Useful for debugging and running nodes from different locations.
This commit is contained in:
cloudhead 2024-01-30 15:57:05 +01:00
parent 921f9f2d76
commit b5b9a55306
No known key found for this signature in database
2 changed files with 15 additions and 4 deletions

View File

@ -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 <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<OsString>,
},
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)?;

View File

@ -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<OsString>,
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()?;