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::ffi::OsString;
use std::path::PathBuf;
use std::time; use std::time;
use anyhow::anyhow; use anyhow::anyhow;
@ -38,6 +39,7 @@ Usage
Start options Start options
--foreground Start the node in the foreground --foreground Start the node in the foreground
--path <path> Start node binary at path (default: radicle-node)
--verbose, -v Verbose output --verbose, -v Verbose output
Routing options Routing options
@ -79,6 +81,7 @@ pub enum Operation {
Start { Start {
foreground: bool, foreground: bool,
verbose: bool, verbose: bool,
path: PathBuf,
options: Vec<OsString>, options: Vec<OsString>,
}, },
Logs { Logs {
@ -118,6 +121,7 @@ impl Args for Options {
let mut lines: usize = 60; let mut lines: usize = 60;
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 path = None;
let mut verbose = false; let mut verbose = false;
while let Some(arg) = parser.next()? { while let Some(arg) = parser.next()? {
@ -166,6 +170,10 @@ impl Args for Options {
Long("verbose") | Short('v') if matches!(op, Some(OperationName::Start)) => { Long("verbose") | Short('v') if matches!(op, Some(OperationName::Start)) => {
verbose = true; 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)) => { Short('n') if matches!(op, Some(OperationName::Logs)) => {
lines = parser.value()?.parse()?; lines = parser.value()?.parse()?;
} }
@ -191,6 +199,7 @@ impl Args for Options {
foreground, foreground,
verbose, verbose,
options, options,
path: path.unwrap_or(PathBuf::from("radicle-node")),
}, },
OperationName::Status => Operation::Status, OperationName::Status => Operation::Status,
OperationName::Sessions => Operation::Sessions, OperationName::Sessions => Operation::Sessions,
@ -226,9 +235,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
Operation::Start { Operation::Start {
foreground, foreground,
options, options,
path,
verbose, verbose,
} => { } => {
control::start(node, !foreground, verbose, options, &profile)?; control::start(node, !foreground, verbose, options, &path, &profile)?;
} }
Operation::Status => { Operation::Status => {
control::status(&node, &profile)?; control::status(&node, &profile)?;

View File

@ -1,7 +1,7 @@
use std::ffi::OsString; use std::ffi::OsString;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader, Read, Seek, SeekFrom}; use std::io::{BufRead, BufReader, Read, Seek, SeekFrom};
use std::{process, thread, time}; use std::{path::Path, process, thread, time};
use localtime::LocalTime; use localtime::LocalTime;
@ -21,6 +21,7 @@ pub fn start(
daemon: bool, daemon: bool,
verbose: bool, verbose: bool,
mut options: Vec<OsString>, mut options: Vec<OsString>,
cmd: &Path,
profile: &Profile, profile: &Profile,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if node.is_running() { if node.is_running() {
@ -54,7 +55,7 @@ pub fn start(
.create(true) .create(true)
.open(profile.home.node().join("node.log"))?; .open(profile.home.node().join("node.log"))?;
let child = process::Command::new("radicle-node") let child = process::Command::new(cmd)
.args(options) .args(options)
.envs(envs) .envs(envs)
.stdin(process::Stdio::null()) .stdin(process::Stdio::null())
@ -94,7 +95,7 @@ pub fn start(
} }
} }
} else { } else {
let mut child = process::Command::new("radicle-node") let mut child = process::Command::new(cmd)
.args(options) .args(options)
.envs(envs) .envs(envs)
.spawn()?; .spawn()?;