diff --git a/sphinx_click/ext.py b/sphinx_click/ext.py index f398aad..9274f73 100644 --- a/sphinx_click/ext.py +++ b/sphinx_click/ext.py @@ -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) diff --git a/tests/test_formatter.py b/tests/test_formatter.py index b55b9d9..6c4029d 100644 --- a/tests/test_formatter.py +++ b/tests/test_formatter.py @@ -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 @@ -200,7 +201,7 @@ def foobar(bar): .. program:: foobar .. code-block:: shell - foobar [OPTIONS] ARG + foobar [OPTIONS] ARG ARG_NO_HELP .. rubric:: Options @@ -216,6 +217,10 @@ def foobar(bar): A sample argument + + .. option:: ARG_NO_HELP + + Required argument """ ).lstrip(), '\n'.join(output),