Skip to content

Commit 66713cc

Browse files
committed
Moved color-disabling into parse_parser to fix subparsers and keep tests working
1 parent cf1fbb7 commit 66713cc

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

sphinxarg/ext.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,11 @@ def run(self):
540540
if 'prog' in self.options:
541541
parser.prog = self.options['prog']
542542

543-
# Argparse in Python 3.14 uses ANSI color codes by default (#72)
544-
if hasattr(parser, 'color'):
545-
parser.color = 'color' in self.options
546-
# Disable colors, unless a flag is present in the user-settings
547-
548543
result = parse_parser(
549544
parser,
550545
skip_default_values='nodefault' in self.options,
551546
skip_default_const_values='nodefaultconst' in self.options,
547+
color='color' in self.options,
552548
)
553549
result = parser_navigate(result, path)
554550
if 'manpage' in self.options:

sphinxarg/parser.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ def _format_usage_without_prefix(parser):
5555

5656

5757
def parse_parser(parser, data=None, **kwargs):
58+
"""Take data from argparse argument parser.
59+
60+
Keyword arguments:
61+
- skip_default_values
62+
- skip_default_const_values
63+
- color
64+
"""
65+
# Argparse in Python 3.14 uses ANSI color codes by default (#72)
66+
if hasattr(parser, 'color'):
67+
parser.color = kwargs.get('color', False)
68+
# Disable colors, unless a flag is presented through user-settings
69+
5870
if data is None:
5971
data = {
6072
'name': '',
@@ -85,6 +97,11 @@ def parse_parser(parser, data=None, **kwargs):
8597
for name, subaction in action._name_parser_map.items():
8698
if name in subsection_alias_names:
8799
continue
100+
101+
if hasattr(subaction, 'color'):
102+
subaction.color = parser.color
103+
# Color is not inherited, must be set again
104+
88105
subalias = subsection_alias[subaction]
89106
subaction.prog = f'{parser.prog} {name}'
90107
subdata = {

0 commit comments

Comments
 (0)