Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help panel sorted by name, allow to not expand help command tables #489

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions typer/rich_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
STYLE_COMMANDS_TABLE_LEADING = 0
STYLE_COMMANDS_TABLE_PAD_EDGE = False
STYLE_COMMANDS_TABLE_PADDING = (0, 1)
STYLE_COMMANDS_TABLE_EXPAND = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this as a separate option that by default behaves as before, is in itself a clean solution!

STYLE_COMMANDS_TABLE_BOX = ""
STYLE_COMMANDS_TABLE_ROW_STYLES = None
STYLE_COMMANDS_TABLE_BORDER_STYLE = None
Expand Down Expand Up @@ -475,13 +476,13 @@ def _print_commands_panel(
"row_styles": STYLE_COMMANDS_TABLE_ROW_STYLES,
"pad_edge": STYLE_COMMANDS_TABLE_PAD_EDGE,
"padding": STYLE_COMMANDS_TABLE_PADDING,
"expand": STYLE_COMMANDS_TABLE_EXPAND,
}
box_style = getattr(box, t_styles.pop("box"), None)

commands_table = Table(
highlight=False,
show_header=False,
expand=True,
box=box_style,
**t_styles,
)
Expand Down Expand Up @@ -636,7 +637,12 @@ def rich_format_help(
markup_mode=markup_mode,
console=console,
)
for panel_name, commands in panel_to_commands.items():

# panel_to_commands is sorted by commands across all panels
# Ordering panels by panel name (except for 'Commands' panel, always printed first)
sorted_panel_to_commands = dict(sorted(panel_to_commands.items()))

for panel_name, commands in sorted_panel_to_commands.items():
if panel_name == COMMANDS_PANEL_TITLE:
# Already printed above
continue
Expand Down
Loading