From 9a7331cead925e8cb502856d7ad18a1dfe5bf18a Mon Sep 17 00:00:00 2001 From: archipelago Date: Sun, 19 Jul 2026 16:49:12 -0400 Subject: [PATCH] fix(cli): --version/-V and --help print and exit instead of booting the daemon A stray `archipelago --version` used to start a full second instance next to the systemd one (issue #74). Handle -V/--version, -h/--help, and reject unknown dashed options before any tracing/state init, mirroring the ceremony subcommand's clean-stdout precedent. Version output matches the health RPC format: -. Fixes #74 Co-Authored-By: Claude Fable 5 --- core/archipelago/src/main.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/archipelago/src/main.rs b/core/archipelago/src/main.rs index 4d1189ea..0b474ea4 100644 --- a/core/archipelago/src/main.rs +++ b/core/archipelago/src/main.rs @@ -98,6 +98,40 @@ async fn main() -> Result<()> { return ceremony::run(); } + // Plain CLI flags must never boot the daemon (a stray `--version` used to + // start a second instance next to the systemd one). Handled before any + // tracing/state init so stdout stays clean. + match std::env::args().nth(1).as_deref() { + Some("--version") | Some("-V") => { + println!( + "archipelago {}-{}", + env!("CARGO_PKG_VERSION"), + option_env!("GIT_HASH").unwrap_or("dev") + ); + return Ok(()); + } + Some("--help") | Some("-h") => { + println!("Archipelago Bitcoin Node OS"); + println!(); + println!("Usage: archipelago [COMMAND]"); + println!(); + println!("Running with no arguments starts the node daemon."); + println!(); + println!("Commands:"); + println!(" ceremony Release-root signing ceremony"); + println!(); + println!("Options:"); + println!(" -V, --version Print version and exit"); + println!(" -h, --help Print this help and exit"); + return Ok(()); + } + Some(other) if other.starts_with('-') => { + eprintln!("archipelago: unknown option '{other}' (see --help)"); + std::process::exit(2); + } + _ => {} + } + let startup_start = std::time::Instant::now(); crash_recovery::init_start_time();