@@ -4079,14 +4079,23 @@ def do_help(self, args: argparse.Namespace) -> None:
4079
4079
self .poutput (self .doc_leader , style = Cmd2Style .HELP_LEADER )
4080
4080
self .poutput ()
4081
4081
4082
- if not cmds_cats :
4083
- # No categories found, fall back to standard behavior
4084
- self ._print_documented_command_topics (self .doc_header , cmds_doc , args .verbose )
4085
- else :
4086
- # Categories found, Organize all commands by category
4087
- for category in sorted (cmds_cats .keys (), key = self .default_sort_key ):
4088
- self ._print_documented_command_topics (category , cmds_cats [category ], args .verbose )
4089
- self ._print_documented_command_topics (self .default_category , cmds_doc , args .verbose )
4082
+ # Print any categories first and then the default category.
4083
+ sorted_categories = sorted (cmds_cats .keys (), key = self .default_sort_key )
4084
+ all_cmds = {category : cmds_cats [category ] for category in sorted_categories }
4085
+ all_cmds [self .doc_header ] = cmds_doc
4086
+
4087
+ # Used to provide verbose table separation for better readability.
4088
+ previous_table_printed = False
4089
+
4090
+ for category , commands in all_cmds .items ():
4091
+ if previous_table_printed :
4092
+ self .poutput ()
4093
+
4094
+ self ._print_documented_command_topics (category , commands , args .verbose )
4095
+ previous_table_printed = bool (commands ) and args .verbose
4096
+
4097
+ if previous_table_printed and (help_topics or cmds_undoc ):
4098
+ self .poutput ()
4090
4099
4091
4100
self .print_topics (self .misc_header , help_topics , 15 , 80 )
4092
4101
self .print_topics (self .undoc_header , cmds_undoc , 15 , 80 )
@@ -4102,7 +4111,7 @@ def do_help(self, args: argparse.Namespace) -> None:
4102
4111
completer = argparse_completer .DEFAULT_AP_COMPLETER (argparser , self )
4103
4112
completer .print_help (args .subcommands , self .stdout )
4104
4113
4105
- # If there is a help func delegate to do_help
4114
+ # If the command has a custom help function, then call it
4106
4115
elif help_func is not None :
4107
4116
help_func ()
4108
4117
0 commit comments