From 8fb260564c3e60c2f2e1a80d8e0d5aba857a5226 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:13:36 -0600 Subject: [PATCH] fleet: serve --help prints domain help instead of starting the daemon (#5488) --- pkgs/fleet/crates/fleet/src/main.rs | 58 +++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/pkgs/fleet/crates/fleet/src/main.rs b/pkgs/fleet/crates/fleet/src/main.rs index 0a85906055..c1c5c0b1cf 100644 --- a/pkgs/fleet/crates/fleet/src/main.rs +++ b/pkgs/fleet/crates/fleet/src/main.rs @@ -403,14 +403,29 @@ fn required_capability(d: &Domain, args: &[String]) -> Result { } } +fn is_help_flag(arg: &str) -> bool { + matches!(arg, "--help" | "-h" | "help") +} + +/// Does this domain invocation ask for the domain help? The plain form +/// puts the flag first (`fleet queue --help`). The `serve` domain's +/// first argument is a role, so its help flag sits one position later +/// (`fleet serve queue-broker --help`) — and the argv0 aliases +/// (`queue-broker --help`) land in exactly that shape after the implied +/// arg is prepended. The broker entry points take no arguments, so a +/// help flag they never see would otherwise start the daemon (#5488). +fn wants_domain_help(d: &Domain, args: &[String]) -> bool { + if args.first().is_some_and(|a| is_help_flag(a)) { + return true; + } + d.name == "serve" && args.get(1).is_some_and(|a| is_help_flag(a)) +} + /// Run one domain invocation (also the argv0-alias landing pad). fn run_domain(surface: &Surface, d: &Domain, args: &[String], invoked_as: &str) -> i32 { // Domain help is registry data: always available, even where the // domain itself is not (§3). - if matches!( - args.first().map(|s| s.as_str()), - Some("--help") | Some("-h") | Some("help") - ) { + if wants_domain_help(d, args) { print_domain_help(surface, d); return EXIT_OK; } @@ -569,3 +584,38 @@ fn _platform_linkage() { #[cfg(feature = "queue")] let _ = std::mem::size_of::(); } + +#[cfg(test)] +mod tests { + use super::*; + + fn args(list: &[&str]) -> Vec { + list.iter().map(|s| s.to_string()).collect() + } + + #[test] + fn help_flag_after_a_serve_role_asks_for_domain_help() { + let serve = domain("serve").expect("serve domain exists"); + for flag in ["--help", "-h", "help"] { + assert!(wants_domain_help(serve, &args(&["queue-broker", flag]))); + assert!(wants_domain_help(serve, &args(&["secrets-broker", flag]))); + assert!(wants_domain_help(serve, &args(&["search", flag]))); + } + // A bare role still starts the daemon; extra args after the + // flag position are the role's own business. + assert!(!wants_domain_help(serve, &args(&["queue-broker"]))); + assert!(!wants_domain_help( + serve, + &args(&["queue-broker", "--bind", "--help"]) + )); + } + + #[test] + fn help_flag_positions_for_other_domains_are_unchanged() { + let queue = domain("queue").expect("queue domain exists"); + assert!(wants_domain_help(queue, &args(&["--help"]))); + // A subcommand's own --help belongs to the domain's parser. + assert!(!wants_domain_help(queue, &args(&["enqueue", "--help"]))); + assert!(!wants_domain_help(queue, &args(&[]))); + } +}