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

Adding STYLE_COMMAND #102

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog: rich-click

## Version 1.6.2dev (2023-03-28)

- Add new style option `STYLE_COMMAND`

## Version 1.6.1 (2023-01-19)

- Don't show metavars for [feature switch](https://click.palletsprojects.com/en/8.1.x/options/#feature-switches) options [[#100](https://github.com/ewels/rich-click/issues/100)] (@likewei92)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ Here is the full list of config options:
# Default styles
STYLE_OPTION = "bold cyan"
STYLE_ARGUMENT = "bold cyan"
STYLE_COMMAND = "bold cyan"
STYLE_SWITCH = "bold green"
STYLE_METAVAR = "bold yellow"
STYLE_METAVAR_APPEND = "dim yellow"
Expand Down
8 changes: 3 additions & 5 deletions src/rich_click/rich_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# Default styles
STYLE_OPTION = "bold cyan"
STYLE_ARGUMENT = "bold cyan"
STYLE_COMMAND = "bold cyan"
STYLE_SWITCH = "bold green"
STYLE_METAVAR = "bold yellow"
STYLE_METAVAR_APPEND = "dim yellow"
Expand Down Expand Up @@ -125,6 +126,7 @@ def _get_rich_console() -> Console:
{
"option": STYLE_OPTION,
"argument": STYLE_ARGUMENT,
"command": STYLE_COMMAND,
"switch": STYLE_SWITCH,
"metavar": STYLE_METAVAR,
"metavar_sep": STYLE_METAVAR_SEPARATOR,
Expand Down Expand Up @@ -362,7 +364,6 @@ def rich_format_help(

# Print command / group help if we have some
if obj.help:

# Print with some padding
console.print(
Padding(
Expand All @@ -378,7 +379,6 @@ def rich_format_help(
argument_group_options = []

for param in obj.get_params(ctx):

# Skip positional arguments - they don't have opts or helptext and are covered in usage
# See https://click.palletsprojects.com/en/8.0.x/documentation/#documenting-arguments
if isinstance(param, click.core.Argument) and not SHOW_ARGUMENTS:
Expand Down Expand Up @@ -408,10 +408,8 @@ def rich_format_help(

# Print each option group panel
for option_group in option_groups:

options_rows = []
for opt in option_group.get("options", []):

# Get the param
for param in obj.get_params(ctx):
if any([opt in param.opts]):
Expand Down Expand Up @@ -565,7 +563,7 @@ class MetavarHighlighter(RegexHighlighter):
**t_styles,
)
# Define formatting in first column, as commands don't match highlighter regex
commands_table.add_column(style="bold cyan", no_wrap=True)
commands_table.add_column(style=STYLE_COMMAND, no_wrap=True)
for command in cmd_group.get("commands", []):
# Skip if command does not exist
if command not in obj.list_commands(ctx):
Expand Down