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

FIX If the help of an argument is None, don't fail #138

Merged
merged 1 commit into from
May 14, 2024
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
5 changes: 3 additions & 2 deletions sphinx_click/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ def _format_argument(arg: click.Argument) -> ty.Generator[str, None, None]:
)
)
# Subclasses of click.Argument may add a `help` attribute (like typer.main.TyperArgument)
if hasattr(arg, 'help'):
help = getattr(arg, 'help', None)
if help:
yield ''
help_string = ANSI_ESC_SEQ_RE.sub('', getattr(arg, 'help'))
help_string = ANSI_ESC_SEQ_RE.sub('', help)
for line in _format_help(help_string):
yield _indent(line)

Expand Down
7 changes: 6 additions & 1 deletion tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def __init__(self, *args, help=None, **kwargs):
@click.command()
@click.option('--option', help='A sample option')
@click.argument('ARG', help='A sample argument', cls=CustomArgument)
@click.argument('ARG_NO_HELP', cls=CustomArgument)
def foobar(bar):
"""A sample command."""
pass
Expand All @@ -200,7 +201,7 @@ def foobar(bar):
.. program:: foobar
.. code-block:: shell

foobar [OPTIONS] ARG
foobar [OPTIONS] ARG ARG_NO_HELP

.. rubric:: Options

Expand All @@ -216,6 +217,10 @@ def foobar(bar):

A sample argument


.. option:: ARG_NO_HELP

Required argument
"""
).lstrip(),
'\n'.join(output),
Expand Down
Loading