@@ -1262,8 +1262,8 @@ impl ChatSession {
12621262 }
12631263 }
12641264 if let Some ( mut args) = input. strip_prefix ( "/" ) . and_then ( shlex:: split) {
1265- // Knowing the first argument is required for error handling .
1266- let first_arg = args. first ( ) . cloned ( ) ;
1265+ // Required for printing errors correctly .
1266+ let orig_args = args. clone ( ) ;
12671267
12681268 // We set the binary name as a dummy name "slash_command" which we
12691269 // replace anytime we error out and print a usage statement.
@@ -1305,20 +1305,19 @@ impl ChatSession {
13051305
13061306 // Print the subcommand help, if available. Required since by default we won't
13071307 // show what the actual arguments are, requiring an unnecessary --help call.
1308- if let (
1309- clap:: error:: ErrorKind :: InvalidValue
1310- | clap:: error:: ErrorKind :: UnknownArgument
1311- | clap:: error:: ErrorKind :: InvalidSubcommand
1312- | clap:: error:: ErrorKind :: MissingRequiredArgument ,
1313- Some ( first_arg) ,
1314- ) = ( err. kind ( ) , first_arg)
1308+ if let clap:: error:: ErrorKind :: InvalidValue
1309+ | clap:: error:: ErrorKind :: UnknownArgument
1310+ | clap:: error:: ErrorKind :: InvalidSubcommand
1311+ | clap:: error:: ErrorKind :: MissingRequiredArgument = err. kind ( )
13151312 {
13161313 let mut cmd = SlashCommand :: command ( ) ;
1317- let help = if let Some ( subcmd) = cmd. find_subcommand_mut ( first_arg) {
1318- subcmd. to_owned ( ) . help_template ( "{all-args}" ) . render_help ( )
1319- } else {
1320- cmd. help_template ( "{all-args}" ) . render_help ( )
1321- } ;
1314+ for arg in & orig_args {
1315+ match cmd. find_subcommand ( arg) {
1316+ Some ( subcmd) => cmd = subcmd. clone ( ) ,
1317+ None => break ,
1318+ }
1319+ }
1320+ let help = cmd. help_template ( "{all-args}" ) . render_help ( ) ;
13221321 writeln ! ( self . stderr, "{}" , help. ansi( ) ) ?;
13231322 }
13241323 } ,
0 commit comments