Skip to content
Open
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
21 changes: 19 additions & 2 deletions tccli/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
from tccli.loaders import CLI_BASE_TYPE


def _escape_help_string(text):
"""Escape '%' characters in help strings for argparse compatibility.

Python 3.14 changed argparse to raise a ValueError ("badly formed help
string") when help strings contain bare '%' characters that are not valid
'%(name)s' format specifiers. API documentation often contains literal
percent signs (e.g. "100%", URL-encoded strings like "%3A").

We replace every '%' with '%%' so that argparse's HelpFormatter renders
the original text unchanged, while no longer tripping over unrecognized
format specifiers.
"""
if not text:
return text
return text.replace('%', '%%')


def str_to_bool(value):
if isinstance(value, bool):
return value
Expand Down Expand Up @@ -143,7 +160,7 @@ def required(self, value):

@property
def documentation(self):
return self._help
return _escape_help_string(self._help)

@property
def cli_type(self):
Expand Down Expand Up @@ -205,7 +222,7 @@ def required(self, value):

@property
def documentation(self):
return self._documentation
return _escape_help_string(self._documentation)

@documentation.setter
def documentation(self, value):
Expand Down