Pre-configured ``--help`` option which immediately prints the help page and exits the program. :param param_decls: One or more option names. Defaults to the single value ``"--help"``. :param kwargs: Extra arguments are passed to :func:`option`.
(*param_decls: str, **kwargs: t.Any)
| 549 | |
| 550 | |
| 551 | def help_option(*param_decls: str, **kwargs: t.Any) -> t.Callable[[FC], FC]: |
| 552 | """Pre-configured ``--help`` option which immediately prints the help page |
| 553 | and exits the program. |
| 554 | |
| 555 | :param param_decls: One or more option names. Defaults to the single |
| 556 | value ``"--help"``. |
| 557 | :param kwargs: Extra arguments are passed to :func:`option`. |
| 558 | """ |
| 559 | |
| 560 | def show_help(ctx: Context, param: Parameter, value: bool) -> None: |
| 561 | """Callback that print the help page on ``<stdout>`` and exits.""" |
| 562 | if value and not ctx.resilient_parsing: |
| 563 | echo(ctx.get_help(), color=ctx.color) |
| 564 | ctx.exit() |
| 565 | |
| 566 | if not param_decls: |
| 567 | param_decls = ("--help",) |
| 568 | |
| 569 | kwargs.setdefault("is_flag", True) |
| 570 | kwargs.setdefault("expose_value", False) |
| 571 | kwargs.setdefault("is_eager", True) |
| 572 | kwargs.setdefault("help", _("Show this message and exit.")) |
| 573 | kwargs.setdefault("callback", show_help) |
| 574 | |
| 575 | return option(*param_decls, **kwargs) |
no test coverage detected