diff --git a/rustfs/src/config/cli.rs b/rustfs/src/config/cli.rs index 59c1dce66..a91f00af6 100644 --- a/rustfs/src/config/cli.rs +++ b/rustfs/src/config/cli.rs @@ -72,6 +72,14 @@ pub fn preprocess_args_for_legacy(args: Vec) -> Vec { if KNOWN_SUBCOMMANDS.contains(&first.as_str()) { return args; } + // Preserve the traditional `rustfs help` entry point without exposing + // Clap's generated `help` subcommand in the top-level command list. + if first == "help" { + let mut out = vec![args[0].clone()]; + out.extend(args[2..].iter().cloned()); + out.push("--help".to_string()); + return out; + } // If first arg is --info, treat it as info subcommand if first == "--info" { let mut out = vec![args[0].clone(), "info".to_string()]; @@ -91,6 +99,7 @@ pub fn preprocess_args_for_legacy(args: Vec) -> Vec { /// Main CLI parser #[derive(Parser, Clone)] #[command(name = "rustfs", version = SHORT_VERSION, long_version = LONG_VERSION)] +#[command(disable_help_subcommand = true)] pub struct Cli { #[command(subcommand)] pub command: Option, @@ -334,3 +343,23 @@ pub fn default_server_opts() -> ServerOpts { buffer_profile: "GeneralPurpose".to_string(), } } + +#[cfg(test)] +mod tests { + use super::{Cli, preprocess_args_for_legacy}; + use clap::Parser; + use clap::error::ErrorKind; + + #[test] + fn preprocess_help_command_displays_top_level_help() { + let args = preprocess_args_for_legacy(vec!["rustfs".to_string(), "help".to_string()]); + + assert_eq!(args, vec!["rustfs".to_string(), "--help".to_string()]); + + let err = match Cli::try_parse_from(args) { + Ok(_) => panic!("rustfs help should display help"), + Err(err) => err, + }; + assert_eq!(err.kind(), ErrorKind::DisplayHelp); + } +}