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

Implement to show the message with --help #2271

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,6 +5,9 @@ Version 8.2.0

Unreleased

- Show deprecation warning message running ``--help`` Option
for ``@click.option``. :issue:`2263`


Version 8.1.3
-------------
Expand Down
11 changes: 11 additions & 0 deletions src/click/core.py
Expand Up @@ -2450,6 +2450,13 @@ class Option(Parameter):
:param help: the help string.
:param hidden: hide this option from help outputs.

:param deprecated: issues a message indicating that
the command is deprecated showing help

.. versionchanged:: 8.2.0
Show deprecation warning message running ``--help`` Option
for ``@click.option``. :issue:`2263`

.. versionchanged:: 8.1.0
Help text indentation is cleaned here instead of only in the
``@option`` decorator.
Expand Down Expand Up @@ -2486,6 +2493,7 @@ def __init__(
hidden: bool = False,
show_choices: bool = True,
show_envvar: bool = False,
deprecated: bool = False,
**attrs: t.Any,
) -> None:
if help:
Expand All @@ -2504,6 +2512,9 @@ def __init__(
else:
prompt_text = prompt

if deprecated:
help = help + "(DEPRECATED)" if help is not None else "(DEPRECATED)"

self.prompt = prompt_text
self.confirmation_prompt = confirmation_prompt
self.prompt_required = prompt_required
Expand Down
10 changes: 10 additions & 0 deletions tests/test_options.py
Expand Up @@ -33,6 +33,16 @@ def test_invalid_option(runner):
assert "'--foo'" in message


def test_deprecated_option(runner):
@click.command()
@click.option("--foo", default="bar", deprecated=True)
def cmd(foo):
click.echo(foo)

result = runner.invoke(cmd, ["--help"])
assert re.search("(DEPRECATED)", result.output)


def test_invalid_nargs(runner):
with pytest.raises(TypeError, match="nargs=-1"):

Expand Down