Skip to content

Commit b3dbb06

Browse files
Fix handling of argparse.SUPPRESS (#149)
* Fix handling of argparse.SUPPRESS * Add test for argparse.SUPPRESS * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 725d518 commit b3dbb06

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

roots/test-suppressed-action/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
from pathlib import Path
5+
6+
sys.path.insert(0, str(Path(__file__).parent))
7+
extensions = ["sphinx_argparse_cli"]
8+
nitpicky = True
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. sphinx_argparse_cli::
2+
:module: parser
3+
:func: make
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from __future__ import annotations
2+
3+
from argparse import SUPPRESS, ArgumentParser
4+
5+
6+
def make() -> ArgumentParser:
7+
parser = ArgumentParser(prog="foo", description="desc", add_help=False)
8+
parser.add_argument(
9+
"--activities-since",
10+
metavar="TIMESTAMP",
11+
help=SUPPRESS,
12+
)
13+
return parser

src/sphinx_argparse_cli/_logic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ def _mk_option_group(self, group: _ArgumentGroup, prefix: str) -> section:
181181
self._register_ref(ref_id, title_text, group_section)
182182
opt_group = bullet_list()
183183
for action in group._group_actions: # noqa: SLF001
184+
if action.help == SUPPRESS:
185+
continue
184186
point = self._mk_option_line(action, prefix)
185187
opt_group += point
186188
group_section += opt_group

tests/test_logic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ def test_usage_width_custom(build_outcome: str) -> None:
120120
assert "complex second [-h] [--flag] [--root]\n" in build_outcome
121121

122122

123+
@pytest.mark.sphinx(buildername="text", testroot="suppressed-action")
124+
def test_suppressed_action(build_outcome: str) -> None:
125+
assert "--activities-since" not in build_outcome
126+
127+
123128
@pytest.mark.parametrize(
124129
("example", "output"),
125130
[

0 commit comments

Comments
 (0)