mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
gh-141679: Add colour to defaults in argparse help (#141680)
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Ubuntu SSL tests with AWS-LC (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / iOS (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Ubuntu SSL tests with AWS-LC (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / iOS (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Co-authored-by: Savannah Ostrowski <savannah@python.org>
This commit is contained in:
parent
227b9d326e
commit
e73fbbacbb
4 changed files with 20 additions and 8 deletions
|
|
@ -168,6 +168,8 @@ class Argparse(ThemeSection):
|
|||
short_option: str = ANSIColors.BOLD_GREEN
|
||||
label: str = ANSIColors.BOLD_YELLOW
|
||||
action: str = ANSIColors.BOLD_GREEN
|
||||
default: str = ANSIColors.GREY
|
||||
default_value: str = ANSIColors.YELLOW
|
||||
reset: str = ANSIColors.RESET
|
||||
error: str = ANSIColors.BOLD_MAGENTA
|
||||
warning: str = ANSIColors.BOLD_YELLOW
|
||||
|
|
|
|||
|
|
@ -748,7 +748,14 @@ class ArgumentDefaultsHelpFormatter(HelpFormatter):
|
|||
if action.default is not SUPPRESS:
|
||||
defaulting_nargs = [OPTIONAL, ZERO_OR_MORE]
|
||||
if action.option_strings or action.nargs in defaulting_nargs:
|
||||
help += _(' (default: %(default)s)')
|
||||
t = self._theme
|
||||
default_str = _(" (default: %(default)s)")
|
||||
prefix, suffix = default_str.split("%(default)s")
|
||||
help += (
|
||||
f" {t.default}{prefix.lstrip()}"
|
||||
f"{t.default_value}%(default)s"
|
||||
f"{t.default}{suffix}{t.reset}"
|
||||
)
|
||||
return help
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7288,6 +7288,8 @@ class TestColorized(TestCase):
|
|||
short_b = self.theme.short_option
|
||||
label_b = self.theme.label
|
||||
pos_b = self.theme.action
|
||||
default = self.theme.default
|
||||
default_value = self.theme.default_value
|
||||
reset = self.theme.reset
|
||||
|
||||
# Act
|
||||
|
|
@ -7314,17 +7316,17 @@ class TestColorized(TestCase):
|
|||
|
||||
{heading}options:{reset}
|
||||
{short_b}-h{reset}, {long_b}--help{reset} show this help message and exit
|
||||
{short_b}-v{reset}, {long_b}--verbose{reset} more spam (default: False)
|
||||
{short_b}-q{reset}, {long_b}--quiet{reset} less spam (default: False)
|
||||
{short_b}-v{reset}, {long_b}--verbose{reset} more spam {default}(default: {default_value}False{default}){reset}
|
||||
{short_b}-q{reset}, {long_b}--quiet{reset} less spam {default}(default: {default_value}False{default}){reset}
|
||||
{short_b}-o{reset}, {long_b}--optional1{reset}
|
||||
{long_b}--optional2{reset} {label_b}OPTIONAL2{reset}
|
||||
pick one (default: None)
|
||||
pick one {default}(default: {default_value}None{default}){reset}
|
||||
{long_b}--optional3{reset} {label_b}{{X,Y,Z}}{reset}
|
||||
{long_b}--optional4{reset} {label_b}{{X,Y,Z}}{reset} pick one (default: None)
|
||||
{long_b}--optional5{reset} {label_b}{{X,Y,Z}}{reset} pick one (default: None)
|
||||
{long_b}--optional6{reset} {label_b}{{X,Y,Z}}{reset} pick one (default: None)
|
||||
{long_b}--optional4{reset} {label_b}{{X,Y,Z}}{reset} pick one {default}(default: {default_value}None{default}){reset}
|
||||
{long_b}--optional5{reset} {label_b}{{X,Y,Z}}{reset} pick one {default}(default: {default_value}None{default}){reset}
|
||||
{long_b}--optional6{reset} {label_b}{{X,Y,Z}}{reset} pick one {default}(default: {default_value}None{default}){reset}
|
||||
{short_b}-p{reset}, {long_b}--optional7{reset} {label_b}{{Aaaaa,Bbbbb,Ccccc,Ddddd}}{reset}
|
||||
pick one (default: None)
|
||||
pick one {default}(default: {default_value}None{default}){reset}
|
||||
{short_b}+f{reset} {label_b}F{reset}
|
||||
{long_b}++bar{reset} {label_b}BAR{reset}
|
||||
{long_b}-+baz{reset} {label_b}BAZ{reset}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Add colour to defaults in :mod:`argparse` help. Patch by Hugo van Kemenade.
|
||||
Loading…
Add table
Add a link
Reference in a new issue