Formatting & Styles
Positional arguments
Section titled “Positional arguments”The default click behaviour is to only show positional arguments in the top usage string, and not in the list below with the options.
If you prefer, you can tell rich-click to show arguments with SHOW_ARGUMENTS.
By default, they will get their own panel, but you can tell rich-click to bundle them together with GROUP_ARGUMENTS_OPTIONS:
help_config = click.RichHelpConfiguration( show_arguments=True, group_arguments_options=True)click.rich_click.SHOW_ARGUMENTS = Trueclick.rich_click.GROUP_ARGUMENTS_OPTIONS = True$ python examples/06_arguments.py --helpUsage: 06_arguments.py [OPTIONS] INPUT OUTPUT {yaml|json} [FLAVOUR] My amazing tool does all the things. This is a minimal example based on documentation from the 'click' package. You can try using --help at the top level and also for specific group subcommands. ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ │ * INPUT PATH [required] │ │ * OUTPUT PATH [required] │ │ * FORMAT {yaml|json} [required] │ │ FLAVOUR TEXT │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ --type TEXT Type of file to sync [default: files] │ │ --all Sync all the things? │ │ --debug Enable debug mode │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯
See
examples/06_arguments.pyfor an example.
Metavars and option choices
Section titled “Metavars and option choices”Metavars are click’s way of showing expected input types.
For example, if you have an option that must be an integer, the metavar is INTEGER.
If you have a choice, the metavar is a list of the possible values.
By default, rich-click shows metavars in their own column. However, if you have a long list of choices, this column can be quite wide and result in a lot of white space:
$ python examples/08_metavars_default.py --helpUsage: 08_metavars_default.py [OPTIONS] My amazing tool does all the things. This is a minimal example based on documentation from the 'click' package. You can try using --help at the top level and also for specific group subcommands. ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ --debug Enable debug mode. │ │ --number [one|two|three|four|five|six|sev This click choice has loads of │ │ en|eight|nine|ten|eleven|twelve| options. │ │ thirteen|fourteen|fifteen|sixtee │ │ n|seventeen|eighteen|nineteen|tw │ │ enty|twenty-one|twenty-two|twent │ │ y-three|twenty-four|twenty-five| │ │ twenty-six|twenty-seven|twenty-e │ │ ight|twenty-nine|thirty] │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯
It may look better to show metavars appended to the help text, instead of in their own column. For this, use the following:
help_config = click.RichHelpConfiguration( show_metavars_column=False, append_metavars_help=True)click.rich_click.SHOW_METAVARS_COLUMN = Falseclick.rich_click.APPEND_METAVARS_HELP = True$ python examples/08_metavars.py --helpUsage: 08_metavars.py [OPTIONS] My amazing tool does all the things. This is a minimal example based on documentation from the 'click' package. You can try using --help at the top level and also for specific group subcommands. ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ --debug Enable debug mode. │ │ --number This click choice has loads of options. │ │ (one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|th │ │ irteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty │ │ |twenty-one|twenty-two|twenty-three|twenty-four|twenty-five|twenty │ │ -six|twenty-seven|twenty-eight|twenty-nine|thirty) │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯
See
examples/08_metavars.pyfor an example.
Error messages
Section titled “Error messages”By default, rich-click gives some nice formatting to error messages:
$ python examples/01_simple.py --hepUsage: 01_simple.py [OPTIONS] COMMAND [ARGS]... Try '01_simple.py --help' for help ╭─ Error ──────────────────────────────────────────────────────────────────────╮ │ No such option '--hep'. Did you mean '--help'? │ ╰──────────────────────────────────────────────────────────────────────────────╯
You can customize the Try ‘command –help’ for help. message with ERRORS_SUGGESTION
using rich-click though, and add some text after the error with ERRORS_EPILOGUE.
For example, from examples/07_custom_errors.py:
help_config = click.RichHelpConfiguration( style_errors_suggestion="magenta italic", errors_suggestion="Try running the '--help' flag for more information.", errors_epilogue="To find out more, visit [link=https://mytool.com]https://mytool.com[/link]")click.rich_click.STYLE_ERRORS_SUGGESTION = "magenta italic"click.rich_click.ERRORS_SUGGESTION = "Try running the '--help' flag for more information."click.rich_click.ERRORS_EPILOGUE = "To find out more, visit [link=https://mytool.com]https://mytool.com[/link]"$ python examples/07_custom_errors.py --hepUsage: 07_custom_errors.py [OPTIONS] INPUT Try running the '--help' flag for more information. ╭─ Error ──────────────────────────────────────────────────────────────────────╮ │ No such option '--hep'. Did you mean '--help'? │ ╰──────────────────────────────────────────────────────────────────────────────╯ To find out more, visit https://mytool.com
See
examples/07_custom_errors.pyfor an example.
Help width
Section titled “Help width”The default behaviour of rich-click is to use the full width of the terminal for output. However, if you’ve carefully crafted your help texts for the default narrow click output, you may find that you now have a lot of whitespace at the side of the panels.
To limit the maximum width of the help output, regardless of the terminal size, set WIDTH in characters as follows:
click.rich_click.WIDTH = 128To still use the full width of the terminal up to a certain limit, set MAX_WIDTH in characters as follows:
click.rich_click.MAX_WIDTH = 96Setting MAX_WIDTH overrides the effect of WIDTH
Styles
Section titled “Styles”Most aspects of rich-click formatting can be customized, from color to alignment.
For example, to print the option flags in a different color, you can use:
click.rich_click.STYLE_OPTION = "magenta"To add a blank line between rows of options, you can use:
click.rich_click.STYLE_OPTIONS_TABLE_LEADING = 1click.rich_click.STYLE_OPTIONS_TABLE_BOX = "SIMPLE"You can make some really horrible colorful solutions using these styles if you wish:
$ python examples/10_table_styles.py --helpUsage: 10_table_styles.py [OPTIONS] COMMAND [ARGS]... My amazing tool does all the things. This is a minimal example based on documentation from the 'click' package. You can try using --help at the top level and also for specific group subcommands. ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ --type TEXT Type of file to sync. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sed mauris euismod, semper leo │ │ quis, sodales augue. Donec posuere nulla quis egestas ornare. Nam efficitur ex quis diam tempus, nec euismod diam │ │ consectetur. Etiam vitae nisi at odio hendrerit dictum in at dui. Aliquam nulla lacus, pellentesque id ultricies sit │ │ amet, mollis nec tellus. Aenean arcu justo, pellentesque viverra justo eget, tempus tincidunt lectus. Maecenas │ │ porttitor risus vitae libero dapibus ullamcorper. Cras faucibus euismod erat in porta. Phasellus cursus gravida ante │ │ vel aliquet. In accumsan enim nec ullamcorper gravida. Donec malesuada dui ac metus tristique cursus. Sed gravida │ │ condimentum fermentum. Ut sit amet nulla commodo, iaculis tellus vitae, accumsan enim. Curabitur mollis semper velit a │ │ suscipit. │ │ │ │ --debug/--no-debug -d/-n Show the debug log messages. Suspendisse dictum hendrerit turpis eu rutrum. Vivamus magna ex, elementum sit amet │ │ sapien laoreet, tempor consequat eros. Morbi semper feugiat nisi eget sodales. Pellentesque et turpis erat. Donec ac │ │ aliquam risus. Nam leo tellus, rutrum et scelerisque vitae, ultrices sed metus. Ut sollicitudin convallis turpis, sit │ │ amet sollicitudin felis semper feugiat. In sapien dui, aliquam eget dui quis, auctor maximus nibh. Suspendisse maximus │ │ sem arcu. Pellentesque sit amet semper est. Cras pulvinar ut tellus a semper. In facilisis tellus odio, non porta nisl │ │ accumsan nec. Pellentesque sollicitudin quam ac felis congue, ac congue enim tempor. │ │ │ │ --version Show the version and exit. │ │ │ │ --help Show this message and exit. │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ╔══════════╦═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗ │ │ ║ auth ║ Authenticate the app. Duis lacus nibh, feugiat a nibh a, commodo dictum libero. Ut ac nulla tincidunt, bibendum nisi vitae, sodales ex. ║ │ │ ║ ║ Vestibulum efficitur, lectus quis venenatis porta, dolor elit varius mauris, consequat interdum lectus est quis mi. Vestibulum imperdiet sed ║ │ │ ║ ║ dolor eget semper. Cras ut mauris ac libero hendrerit congue. Vivamus pretium nunc turpis, eget imperdiet sapien tempor auctor. Phasellus ║ │ │ ║ ║ risus nisi, laoreet in posuere sit amet, sodales non diam. Aliquam non malesuada urna, a faucibus risus. ║ │ │ ╠══════════╬═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣ │ │ ║ config ║ Set up the configuration. Sed accumsan ornare odio dictum aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ║ │ │ ║ ║ ac turpis egestas. Curabitur in pellentesque mauris. Nulla mollis dui finibus, dictum neque id, suscipit nisl. Nunc mauris ex, laoreet nec ║ │ │ ║ ║ tincidunt ut, pellentesque ut tortor. Mauris fermentum diam at porttitor tempor. Aliquam euismod nisi massa, nec placerat ante euismod quis. ║ │ │ ╠══════════╬═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣ │ │ ║ download ║ Pretend to download some files from somewhere. Integer bibendum libero nunc, sed aliquet ex tincidunt vel. Duis vitae sem vel odio luctus ║ │ │ ║ ║ suscipit nec vitae enim. Curabitur vel lectus nec quam maximus dapibus. Phasellus eros velit, maximus non hendrerit nec, tempor fringilla ║ │ │ ║ ║ urna. Vivamus vel nibh quis sapien consectetur fermentum. Curabitur at ultrices quam, vel molestie justo. Nunc lobortis orci vel nibh ║ │ │ ║ ║ sagittis pretium. Morbi rhoncus sapien luctus, ultrices urna vel, convallis tortor. ║ │ │ ╠══════════╬═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣ │ │ ║ sync ║ Synchronise all your files between two places. Curabitur congue eget lorem in lacinia. Praesent tempus nunc nec nulla dignissim, et lacinia ║ │ │ ║ ║ ipsum accumsan. Duis sodales, sapien at fermentum condimentum, diam metus porttitor lacus, nec gravida mi diam eget ligula. Pellentesque ║ │ │ ║ ║ elementum at justo a luctus. Mauris a interdum odio. Maecenas in consectetur velit. Ut tristique congue felis at tempus. Donec pulvinar ║ │ │ ║ ║ tortor ut odio posuere imperdiet. Fusce lacinia iaculis diam in scelerisque. Pellentesque in lorem est. Nulla efficitur luctus lacus, auctor ║ │ │ ║ ║ auctor dui hendrerit a. Ut nec iaculis dolor. Morbi metus lectus, aliquet et sapien nec, congue euismod lorem. Pellentesque tristique tempus ║ │ │ ║ ║ augue at convallis. ║ │ │ ╚══════════╩═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
See
examples/10_table_styles.pyfor an example.
See the Configuration options section below for the full list of available options.