Skip to content

Commit 16dd132

Browse files
committed
Display argument name where exist
Signed-off-by: Bernát Gábor <[email protected]>
1 parent c13e806 commit 16dd132

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

.github/workflows/check.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ jobs:
5252
PYTEST_ADDOPTS: "-vv --durations=20"
5353
CI_RUN: "yes"
5454
DIFF_AGAINST: HEAD
55-
- name: rename coverage report file
56-
run: |
57-
import os; os.rename('.tox/coverage.{}.xml'.format(os.environ['TOXENV']), '.tox/coverage.xml')
58-
shell: python
59-
- uses: codecov/codecov-action@v1
60-
with:
61-
file: ./.tox/coverage.xml
62-
flags: tests
63-
name: ${{ matrix.py }} - ${{ matrix.os }}
6455

6556
check:
6657
name: check ${{ matrix.tox_env }} - ${{ matrix.os }}

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## 1.4.0 (2021-02-14)
5+
## 1.5.0 (2021-02-13)
6+
7+
- Display the metavar (fallback to dest) if the action has more than one argument (this is inline with how usage is
8+
displayed).
9+
10+
## 1.4.0 (2021-02-13)
611

712
- Command line arguments are now bold to highlight them even further from the help text
813

@@ -12,7 +17,8 @@ All notable changes to this project will be documented in this file.
1217
- Mark document as always needs update (as the underlying content is coming from outside the sphinx documents)
1318
- Help messages is now interpreted as reStructuredText
1419
- Matching curly braces, single and double quotes in help text will be marked as string literals
15-
- Help messages containing the ``default(s)`` word do not show the default value (as often this indicates the default is already documented in the help text)
20+
- Help messages containing the `default(s)` word do not show the default value (as often this indicates the default is
21+
already documented in the help text)
1622

1723
## 1.2.0 (2021-02-05)
1824

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
[![PyPI - Downloads](https://img.shields.io/pypi/dm/sphinx-argparse-cli?style=flat-square)](https://pypistats.org/packages/sphinx-argparse-cli)
77
[![PyPI - License](https://img.shields.io/pypi/l/sphinx-argparse-cli?style=flat-square)](https://opensource.org/licenses/MIT)
88
![check](https://github.com/gaborbernat/sphinx-argparse-cli/workflows/check/badge.svg?branch=main)
9-
[![codecov](https://codecov.io/gh/gaborbernat/sphinx-argparse-cli/branch/main/graph/badge.svg)](https://codecov.io/gh/pypa/virtualenv)
109
[![Code style:
1110
black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)
1211

roots/test-complex/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ def make() -> ArgumentParser:
77
parser = ArgumentParser(description="argparse tester", prog="complex")
88
parser.add_argument("--root", action="store_true", help="root flag")
99
parser.add_argument("--no-help", action="store_true")
10+
parser.add_argument("--outdir", "-o", type=str, help="output directory", metavar="out_dir")
11+
parser.add_argument("--in-dir", "-i", type=str, help="input directory", dest="in_dir")
1012

1113
group = parser.add_argument_group("Exclusive", description="this is an exclusive group")
1214
exclusive = group.add_mutually_exclusive_group()

src/sphinx_argparse_cli/_logic.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,22 @@ def _mk_option_group(self, group: _ArgumentGroup, prefix: str) -> section:
139139

140140
def _mk_option_line(self, action: Action, prefix: str) -> list_item: # noqa
141141
line = paragraph()
142+
as_key = action.dest
143+
if action.metavar:
144+
as_key = action.metavar if isinstance(action.metavar, str) else action.metavar[0]
142145
if action.option_strings:
143146
first = True
147+
is_flag = action.nargs == 0
144148
for opt in action.option_strings:
145149
if first:
146150
first = False
147151
else:
148152
line += Text(", ")
149153
self._mk_option_name(line, prefix, opt)
154+
if not is_flag:
155+
line += Text(" ")
156+
line += literal(text=as_key.upper())
150157
else:
151-
as_key = (
152-
action.dest
153-
if action.metavar is None
154-
else (action.metavar if isinstance(action.metavar, str) else action.metavar[0])
155-
)
156158
self._mk_option_name(line, prefix, as_key)
157159

158160
point = list_item("", line, ids=[])

tests/complex.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ complex - CLI interface
33

44
argparse tester
55

6-
complex [-h] [--root] [--no-help] [--foo | --bar] {first,f,second,third} ...
6+
complex [-h] [--root] [--no-help] [--outdir out_dir] [--in-dir IN_DIR] [--foo | --bar]
7+
{first,f,second,third} ...
78

89

910
optional arguments
@@ -15,6 +16,12 @@ optional arguments
1516

1617
* **"--no-help"** (default: "False")
1718

19+
* **"--outdir"** "OUT_DIR", **"-o"** "OUT_DIR" - output directory
20+
(default: "None")
21+
22+
* **"--in-dir"** "IN_DIR", **"-i"** "IN_DIR" - input directory
23+
(default: "None")
24+
1825

1926
Exclusive
2027
=========

0 commit comments

Comments
 (0)