Repository: pallets/click
File: src/click/decorators.py (Python)

Code before:

        echo(
            message % {"prog": prog_name, "package": package_name, "version": version},
            color=ctx.color,
        )
        ctx.exit()

    if not param_decls:
        param_decls = ("--version",)

    kwargs.setdefault("is_flag", True)
    kwargs.setdefault("expose_value", False)
    kwargs.setdefault("is_eager", True)
    kwargs.setdefault("help", _("Show the version and exit."))
    kwargs["callback"] = callback
    return option(*param_decls, **kwargs)


class HelpOption(Option):
    """Pre-configured ``--help`` option which immediately prints the help page
    and exits the program.
    """

    def __init__(
        self,
        param_decls: t.Optional[t.Sequence[str]] = None,
        **kwargs: t.Any,
    ) -> None:
        if not param_decls:
            param_decls = ("--help",)

        kwargs.setdefault("is_flag", True)
        kwargs.setdefault("expose_value", False)
        kwargs.setdefault("is_eager", True)
        kwargs.setdefault("help", _("Show this message and exit."))
        kwargs.setdefault("callback", self.show_help)

        super().__init__(param_decls, **kwargs)

    @staticmethod
    def show_help(ctx: Context, param: Parameter, value: bool) -> None:
        """Callback that print the help page on ``<stdout>`` and exits."""
        if value and not ctx.resilient_parsing:
            echo(ctx.get_help(), color=ctx.color)
            ctx.exit()


def help_option(*param_decls: str, **kwargs: t.Any) -> t.Callable[[FC], FC]:
    """Decorator for the pre-configured ``--help`` option defined above.

    :param param_decls: One or more option names. Defaults to the single

Review comment (suggestion):
```suggestion
        param_decls: abc.Sequence[str] | None = None,
```

Code after:
            )

        echo(
            message % {"prog": prog_name, "package": package_name, "version": version},
            color=ctx.color,
        )
        ctx.exit()

    if not param_decls:
        param_decls = ("--version",)

    kwargs.setdefault("is_flag", True)
    kwargs.setdefault("expose_value", False)
    kwargs.setdefault("is_eager", True)
    kwargs.setdefault("help", _("Show the version and exit."))
    kwargs["callback"] = callback
    return option(*param_decls, **kwargs)


class HelpOption(Option):
    """Pre-configured ``--help`` option which immediately prints the help page
    and exits the program.
    """

    def __init__(
        self,
        param_decls: abc.Sequence[str] | None = None,
        **kwargs: t.Any,
    ) -> None:
        if not param_decls:
            param_decls = ("--help",)

        kwargs.setdefault("is_flag", True)
        kwargs.setdefault("expose_value", False)
        kwargs.setdefault("is_eager", True)
        kwargs.setdefault("help", _("Show this message and exit."))
        kwargs.setdefault("callback", self.show_help)

        super().__init__(param_decls, **kwargs)

    @staticmethod
    def show_help(ctx: Context, param: Parameter, value: bool) -> None:
        """Callback that print the help page on ``<stdout>`` and exits."""
        if value and not ctx.resilient_parsing:
            echo(ctx.get_help(), color=ctx.color)
            ctx.exit()


def help_option(*param_decls: str, **kwargs: t.Any) -> t.Callable[[FC], FC]:
    """Decorator for the pre-configured ``--help`` option defined above.