Skip to content

Commit

Permalink
Do not print suppressed group names
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdanal committed May 9, 2024
1 parent aae5e4c commit f0434ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

## Unreleased

### Breaking changes
- Drop support for Python 3.7
* Issue [#95](https://github.com/hamdanal/rich-argparse/issues/95),
PR [#103](https://github.com/hamdanal/rich-argparse/pull/103)

### Features
- Python 3.13 is now officially supported
* PR [#103](https://github.com/hamdanal/rich-argparse/pull/103)

### Fixes
- Do not print suppressed group names
* Issue [#115](https://github.com/hamdanal/rich-argparse/issues/115),
PR [#116](https://github.com/hamdanal/rich-argparse/pull/116)

## 1.4.0 - 2023-10-21

### Features
Expand Down
4 changes: 2 additions & 2 deletions rich_argparse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class _Section(argparse.HelpFormatter._Section):
def __init__(
self, formatter: RichHelpFormatter, parent: Self | None, heading: str | None = None
) -> None:
if heading is not None:
if heading is not argparse.SUPPRESS and heading is not None:
heading = f"{type(formatter).group_name_formatter(heading)}:"
super().__init__(formatter, parent, heading)
self.formatter: RichHelpFormatter
Expand Down Expand Up @@ -165,7 +165,7 @@ def _render_actions(self, console: r.Console, options: r.ConsoleOptions) -> r.Re
def __rich_console__(self, console: r.Console, options: r.ConsoleOptions) -> r.RenderResult:
if not self.rich_items and not self.rich_actions:
return # empty section
if self.heading:
if self.heading is not argparse.SUPPRESS and self.heading is not None:
yield r.Text(self.heading, style="argparse.groups")
yield from self._render_items(console, options)
yield from self._render_actions(console, options)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def test_overall_structure(prog, usage, description, epilog):
parsers.add_argument_group("", description="empty_name_empty_group description")
parsers.add_argument_group(description="no_name_empty_group description")
parsers.add_argument_group("spaces group", description=" \tspaces_group description ")
parsers.add_argument_group(SUPPRESS, description="suppressed_name_group description")
parsers.add_argument_group(SUPPRESS, description=SUPPRESS)

# all types of non-empty groups
groups = parsers.add_argument_group("group name", description="group description")
Expand All @@ -159,6 +161,14 @@ def test_overall_structure(prog, usage, description, epilog):
no_name_groups.add_argument("arg", help="arg help inside no_name_group")
no_name_no_desc_groups = parsers.add_argument_group()
no_name_no_desc_groups.add_argument("arg", help="arg help inside no_name_no_desc_group")
suppressed_name_groups = parsers.add_argument_group(
SUPPRESS, description="suppressed_name_group description"
)
suppressed_name_groups.add_argument("arg", help="arg help inside suppressed_name_group")
suppressed_name_desc_groups = parsers.add_argument_group(SUPPRESS, description=SUPPRESS)
suppressed_name_desc_groups.add_argument(
"arg", help="arg help inside suppressed_name_desc_group"
)

parsers.assert_format_help_equal()

Expand Down

0 comments on commit f0434ac

Please sign in to comment.