Skip to content
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
8 changes: 8 additions & 0 deletions roots/test-tuple-metavar/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent))
extensions = ["sphinx_argparse_cli"]
nitpicky = True
3 changes: 3 additions & 0 deletions roots/test-tuple-metavar/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. sphinx_argparse_cli::
:module: parser
:func: make
10 changes: 10 additions & 0 deletions roots/test-tuple-metavar/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

from argparse import ArgumentParser


def make() -> ArgumentParser:
parser = ArgumentParser(prog="tool")
parser.add_argument("--pair", nargs=2, metavar=("A", "B"), help="select a pair")
parser.add_argument("--val", metavar="VAL", help="single val")
return parser
8 changes: 7 additions & 1 deletion src/sphinx_argparse_cli/_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ def _mk_option_line(self, action: Action, prefix: str) -> list_item:
self._mk_option_name(line, prefix, opt)
if not is_flag:
line += Text(" ")
line += literal(text=as_key.upper())
metavar_text = (
" ".join(meta.upper() for meta in action.metavar)
if isinstance(action.metavar, tuple)
else as_key.upper()
)
line += literal(text=metavar_text)
else:
self._mk_option_name(line, prefix, as_key)

Expand All @@ -282,6 +287,7 @@ def _mk_option_line(self, action: Action, prefix: str) -> list_item:
line += content
if (
"no_default_values" not in self.options
and action.default is not None
and action.default != SUPPRESS
and not re.match(r".*[ (]default[s]? .*", (action.help or ""))
and not isinstance(action, _StoreTrueAction | _StoreFalseAction)
Expand Down
6 changes: 2 additions & 4 deletions tests/complex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ complex options
* **"--no-help"**

* **"--outdir"** "OUT_DIR", **"-o"** "OUT_DIR" - output directory
(default: "None")

* **"--in-dir"** "IN_DIR", **"-i"** "IN_DIR" - input directory
(default: "None")


complex Exclusive
Expand All @@ -44,7 +42,7 @@ a-first-desc
complex first positional arguments
----------------------------------

* **"one"** - first positional argument (default: "None")
* **"one"** - first positional argument

* **"pos_two"** - second positional argument (default: "1")

Expand All @@ -68,7 +66,7 @@ complex second
complex second positional arguments
-----------------------------------

* **"one"** - first positional argument (default: "None")
* **"one"** - first positional argument

* **"pos_two"** - second positional argument (default: "green")

Expand Down
6 changes: 2 additions & 4 deletions tests/complex_pre_310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ complex optional arguments
* **"--no-help"**

* **"--outdir"** "OUT_DIR", **"-o"** "OUT_DIR" - output directory
(default: "None")

* **"--in-dir"** "IN_DIR", **"-i"** "IN_DIR" - input directory
(default: "None")


complex Exclusive
Expand All @@ -44,7 +42,7 @@ a-first-desc
complex first positional arguments
----------------------------------

* **"one"** - first positional argument (default: "None")
* **"one"** - first positional argument

* **"pos_two"** - second positional argument (default: "1")

Expand All @@ -68,7 +66,7 @@ complex second
complex second positional arguments
-----------------------------------

* **"one"** - first positional argument (default: "None")
* **"one"** - first positional argument

* **"pos_two"** - second positional argument (default: "green")

Expand Down
13 changes: 11 additions & 2 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,9 @@ def test_nargs(build_outcome: str) -> None:
assert "pos_optional" in build_outcome
assert "pos_zero_or_more" in build_outcome
assert "pos_one_or_more" in build_outcome
assert "KEY" in build_outcome
assert "VALUE" in build_outcome
assert "KEY VALUE" in build_outcome
assert "(default: " in build_outcome # default_val is not None, should show
assert 'default: "None"' not in build_outcome


@pytest.mark.sphinx(buildername="text", testroot="choices")
Expand All @@ -381,3 +382,11 @@ def test_actions(build_outcome: str) -> None:
assert "increase verbosity" in build_outcome
assert "paths to include" in build_outcome
assert "a required optional argument" in build_outcome


@pytest.mark.sphinx(buildername="text", testroot="tuple-metavar")
def test_tuple_metavar(build_outcome: str) -> None:
assert '"A B"' in build_outcome or "A B" in build_outcome
assert "select a pair" in build_outcome
assert "default: None" not in build_outcome
assert '"VAL"' in build_outcome