Skip to content

Commit 17c6a96

Browse files
committed
Prefer parser description over help message
Signed-off-by: Bernát Gábor <[email protected]>
1 parent 96c94cb commit 17c6a96

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## 1.5.1 (2021-04-15)
6+
7+
- For sub-commands use the parser description first as description and only then fallback to the help message
8+
59
## 1.5.0 (2021-02-13)
610

711
- Display the metavar (fallback to dest) if the action has more than one argument (this is inline with how usage is

roots/test-complex/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def make() -> ArgumentParser:
2121
sub_parsers_a.required = False
2222
sub_parsers_a.default = "first"
2323

24-
a_parser_first = sub_parsers_a.add_parser("first", aliases=["f"], help="a-first-help")
24+
a_parser_first = sub_parsers_a.add_parser("first", aliases=["f"], help="a-first-help", description="a-first-desc")
2525
a_parser_first.add_argument("--flag", dest="a_par_first_flag", action="store_true", help="a parser first flag")
2626
a_parser_first.add_argument("--root", action="store_true", help="root flag")
2727
a_parser_first.add_argument("pos_one", help="first positional argument", metavar="one")

src/sphinx_argparse_cli/_logic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ def _mk_sub_command(self, aliases: list[str], help_msg: str, parser: ArgumentPar
186186
if aliases:
187187
title_text += f" ({', '.join(aliases)})"
188188
group_section = section("", title("", Text(title_text)), ids=[make_id(title_text)], names=[title_text])
189-
if help_msg:
190-
desc_paragraph = paragraph("", Text(help_msg))
189+
190+
command_desc = (parser.description or help_msg or "").strip()
191+
if command_desc:
192+
desc_paragraph = paragraph("", Text(command_desc))
191193
group_section += desc_paragraph
192194
group_section += self._mk_usage(parser)
193195
for group in parser._action_groups: # noqa

tests/complex.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ this is an exclusive group
3636
complex first (f)
3737
=================
3838

39-
a-first-help
39+
a-first-desc
4040

4141
complex first [-h] [--flag] [--root] one pos_two
4242

0 commit comments

Comments
 (0)