Panels - Tips
There are a few things to keep in mind when using RichPanels.
Handling --help option
Section titled “Handling --help option”The help option is associated with the default options panel.
If you define all the panels, the --help option will be left straggling in the default panel.
This is probably a mistake, and there are two ways to fix it:
# /// script# dependencies = ["rich-click>=1.9"]# ///
# The --help option will just be in its own panel at the top.# This is probably not what is intended!def move_item(src, dest, env, log_level): """Move an item from a src location to a dest location""" pass
if __name__ == "__main__": move_item()Output - Mistake
$ python panels_handling_help_mistake.py --helpUsage: panels_handling_help_mistake.py [OPTIONS] Move an item from a src location to a dest location ╭─ Main ───────────────────────────────────────────────────────────────────────╮ │ --src TEXT │ │ --dest TEXT │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Extra ──────────────────────────────────────────────────────────────────────╮ │ --env TEXT │ │ --log-level TEXT │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯
# /// script# dependencies = ["rich-click>=1.9"]# ///
# Explicitly define the panels and place --help in Extra:def move_item(src, dest, env, log_level): """Move an item from a src location to a dest location""" pass
if __name__ == "__main__": move_item()Output - Fix (method 1)
$ python panels_handling_help_fix_1.py --helpUsage: panels_handling_help_fix_1.py [OPTIONS] Move an item from a src location to a dest location ╭─ Main ───────────────────────────────────────────────────────────────────────╮ │ --src TEXT │ │ --dest TEXT │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Extra ──────────────────────────────────────────────────────────────────────╮ │ --env TEXT │ │ --log-level TEXT │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯
# /// script# dependencies = ["rich-click>=1.9"]# ///
# Explicitly define the help_option() and set its panel.def move_item(src, dest, env, log_level): """Move an item from a src location to a dest location""" pass
if __name__ == "__main__": move_item()Output - Fix (method 2)
$ python panels_handling_help_fix_2.py --helpUsage: panels_handling_help_fix_2.py [OPTIONS] Move an item from a src location to a dest location ╭─ Main ───────────────────────────────────────────────────────────────────────╮ │ --src TEXT │ │ --dest TEXT │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Extra ──────────────────────────────────────────────────────────────────────╮ │ --env TEXT │ │ --log-level TEXT │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯
Sort order of panels
Section titled “Sort order of panels”Panels are printed in the order that they are defined, from top to bottom.
@click.option_panel("first")@click.command_panel("second")@click.option_panel("third")If panels are inferred from @click.option(panel=...), rather than defined by @click.option_panel(), then they are defined in the order that they appear in parameters from top to bottom.
The simplest way to control the order panels is to define them explicitly!
This also means that you can order options panels to come before command panels, and vice-versa, based on the decorator order.
Ordering of rows within panels
Section titled “Ordering of rows within panels”The easiest way to control the order of elements within a panel is to explicitly define the order within the panel itself.
If you are having trouble with ordering things, set the order within options= or commands=.
Additionally, it is suggested you set every object you intend on including in the panel.
# /// script# dependencies = ["rich-click>=1.9"]# ///
def move_item(src, dest, env, log_level): """Move an item from a src location to a dest location""" pass
if __name__ == "__main__": move_item()Output
$ python panels_row_order.py --helpUsage: panels_row_order.py [OPTIONS] Move an item from a src location to a dest location ╭─ Extra ──────────────────────────────────────────────────────────────────────╮ │ --env TEXT │ │ --log-level TEXT │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Main ───────────────────────────────────────────────────────────────────────╮ │ --src TEXT │ │ --dest TEXT │ ╰──────────────────────────────────────────────────────────────────────────────╯
That said, the default behavior is also predictable and follows what base Click does for ordering:
- Arguments + options are presented in the order they occur in the decorators, from top to bottom.
- Subcommands are alphanumerically sorted.