From f084eeb1f4e9db6575a21bd305b0dc81b158a6f0 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Wed, 4 Nov 2026 10:08:24 -0600 Subject: [PATCH] fix(fleet): reject trailing arguments on root built-ins (#5572) --- pkgs/fleet/crates/fleet/src/main.rs | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pkgs/fleet/crates/fleet/src/main.rs b/pkgs/fleet/crates/fleet/src/main.rs index 3719689033..cb0f6a51d0 100644 --- a/pkgs/fleet/crates/fleet/src/main.rs +++ b/pkgs/fleet/crates/fleet/src/main.rs @@ -571,6 +571,17 @@ fn cmd_init(surface: &Surface, args: &[String], invoked_as: &str) -> i32 { } } +/// Root built-ins take no arguments: a trailing argument is a usage +/// error naming it (#5572), not silently discarded output. +fn reject_extra_args(args: &[String]) -> Option { + args.get(1).map(|extra| { + usage_error(&format!( + "unexpected argument '{extra}' for 'fleet {}'", + args.first().map(|s| s.as_str()).unwrap_or("") + )) + }) +} + fn run_root(surface: &Surface, args: &[String], invoked_as: &str) -> i32 { let first = args.first().map(|s| s.as_str()); match first { @@ -597,14 +608,23 @@ fn run_root(surface: &Surface, args: &[String], invoked_as: &str) -> i32 { )), }, Some("--version") | Some("-V") => { + if let Some(code) = reject_extra_args(args) { + return code; + } println!("fleet {VERSION}"); EXIT_OK } Some("version") => { + if let Some(code) = reject_extra_args(args) { + return code; + } print_version(surface, invoked_as); EXIT_OK } Some("capabilities") => { + if let Some(code) = reject_extra_args(args) { + return code; + } print_capabilities(surface, invoked_as); EXIT_OK } @@ -713,4 +733,23 @@ mod tests { assert!(!wants_domain_help(queue, &args(&["enqueue", "--help"]))); assert!(!wants_domain_help(queue, &args(&[]))); } + + #[test] + fn root_builtins_reject_trailing_arguments() { + // #5572: version / capabilities / --version silently discarded + // trailing arguments and returned success. + let surface = Surface::new(None, fleet_config::Config::default()); + for cmd in ["version", "capabilities", "--version", "-V"] { + assert_eq!( + run_root(&surface, &args(&[cmd, "--bogus"]), "fleet"), + EXIT_USAGE, + "{cmd} must reject a trailing argument" + ); + assert_eq!( + run_root(&surface, &args(&[cmd]), "fleet"), + EXIT_OK, + "bare {cmd} stays accepted" + ); + } + } }