@@ -1262,8 +1262,8 @@ impl ChatSession {
1262
1262
}
1263
1263
}
1264
1264
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 ( ) ;
1267
1267
1268
1268
// We set the binary name as a dummy name "slash_command" which we
1269
1269
// replace anytime we error out and print a usage statement.
@@ -1305,20 +1305,19 @@ impl ChatSession {
1305
1305
1306
1306
// Print the subcommand help, if available. Required since by default we won't
1307
1307
// 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 ( )
1315
1312
{
1316
1313
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 ( ) ;
1322
1321
writeln ! ( self . stderr, "{}" , help. ansi( ) ) ?;
1323
1322
}
1324
1323
} ,
0 commit comments