Skip to content

Commit

Permalink
Deduplicate default help name definition
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Jan 10, 2025
1 parent b77007d commit 1250a26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 4 additions & 1 deletion click_extra/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ def default_extra_params() -> list[Option]:
]


DEFAULT_HELP_NAMES = ("--help", "-h")


class ExtraCommand(ExtraHelpColorsMixin, Command): # type: ignore[misc]
"""Like ``cloup.command``, with sane defaults and extra help screen colorization."""

Expand Down Expand Up @@ -302,7 +305,7 @@ def __init__(
default_ctx_settings: dict[str, Any] = {
# Click settings:
# "default_map": {"verbosity": "DEBUG"},
"help_option_names": ("--help", "-h"),
"help_option_names": DEFAULT_HELP_NAMES,
"show_default": True,
# Cloup settings:
"align_option_groups": False,
Expand Down
7 changes: 3 additions & 4 deletions click_extra/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import cloup

from .colorize import ColorOption
from .commands import ExtraCommand, ExtraGroup, default_extra_params
from .commands import DEFAULT_HELP_NAMES, ExtraCommand, ExtraGroup, default_extra_params
from .config import ConfigOption
from .logging import VerbosityOption
from .parameters import ShowParamsOption
Expand Down Expand Up @@ -95,10 +95,9 @@ def decorator(*args, **kwargs):
# TODO: try the following instead once https://github.com/pallets/click/pull/2840
# is merged:
# dec=click.decorators.help_option,
# param_decls=("--help", "-h"),
# param_decls=DEFAULT_HELP_NAMES,
click.decorators.help_option,
"--help",
"-h",
*DEFAULT_HELP_NAMES,
)

# Copy Click and Cloup decorators with better defaults, and prefix them with "extra_".
Expand Down

0 comments on commit 1250a26

Please sign in to comment.