@@ -466,6 +466,7 @@ def _print_commands_panel(
466
466
commands : List [click .Command ],
467
467
markup_mode : MarkupMode ,
468
468
console : Console ,
469
+ cmd_len : int ,
469
470
) -> None :
470
471
t_styles : Dict [str , Any ] = {
471
472
"show_lines" : STYLE_COMMANDS_TABLE_SHOW_LINES ,
@@ -487,7 +488,16 @@ def _print_commands_panel(
487
488
)
488
489
# Define formatting in first column, as commands don't match highlighter
489
490
# regex
490
- commands_table .add_column (style = "bold cyan" , no_wrap = True )
491
+ commands_table .add_column (
492
+ style = "bold cyan" ,
493
+ no_wrap = True ,
494
+ width = cmd_len ,
495
+ )
496
+
497
+ # A big ratio makes the description column be greedy and take all the space
498
+ # available instead of allowing the command column to grow and misalign with
499
+ # other panels.
500
+ commands_table .add_column ("Description" , justify = "left" , no_wrap = False , ratio = 10 )
491
501
rows : List [List [Union [RenderableType , None ]]] = []
492
502
deprecated_rows : List [Union [RenderableType , None ]] = []
493
503
for command in commands :
@@ -628,13 +638,23 @@ def rich_format_help(
628
638
)
629
639
panel_to_commands [panel_name ].append (command )
630
640
641
+ # Identify the longest command name in all panels
642
+ max_cmd_len = max (
643
+ [
644
+ len (command .name or "" )
645
+ for commands in panel_to_commands .values ()
646
+ for command in commands
647
+ ]
648
+ )
649
+
631
650
# Print each command group panel
632
651
default_commands = panel_to_commands .get (COMMANDS_PANEL_TITLE , [])
633
652
_print_commands_panel (
634
653
name = COMMANDS_PANEL_TITLE ,
635
654
commands = default_commands ,
636
655
markup_mode = markup_mode ,
637
656
console = console ,
657
+ cmd_len = max_cmd_len ,
638
658
)
639
659
for panel_name , commands in panel_to_commands .items ():
640
660
if panel_name == COMMANDS_PANEL_TITLE :
@@ -645,6 +665,7 @@ def rich_format_help(
645
665
commands = commands ,
646
666
markup_mode = markup_mode ,
647
667
console = console ,
668
+ cmd_len = max_cmd_len ,
648
669
)
649
670
650
671
# Epilogue if we have it
0 commit comments