import argparse
import sys
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument('infile', nargs='?', default='-',
help='the file to parse; defaults to stdin')
parser.add_argument('-m', '--mode', default='exec',
def main(args=None):
import argparse
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
textgroup = parser.add_argument_group('text only arguments')
htmlgroup = parser.add_argument_group('html only arguments')
textgroup.add_argument(
if __name__ == "__main__":
import argparse
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument('-q', action='store_true',
help="don't print version and copyright messages")
args = parser.parse_args()
import argparse
parser = argparse.ArgumentParser(
- description='Utilities to support installing Python libraries.')
+ description='Utilities to support installing Python libraries.',
+ color=True,
+ )
parser.add_argument('-l', action='store_const', const=0,
default=None, dest='maxlevels',
help="don't recurse into subdirectories")
def main(args=None):
import argparse
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument('-C', '--show-caches', action='store_true',
help='show inline caches')
parser.add_argument('-O', '--show-offsets', action='store_true',
def _test():
import argparse
- parser = argparse.ArgumentParser(description="doctest runner")
+ parser = argparse.ArgumentParser(description="doctest runner", color=True)
parser.add_argument('-v', '--verbose', action='store_true', default=False,
help='print very verbose output for all tests')
parser.add_argument('-o', '--option', action='append',
def _main(argv=None):
import argparse
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument(
"--version",
action="version",
from argparse import ArgumentParser
parser = ArgumentParser(description=
"A simple command line interface for the gzip module: act like gzip, "
- "but do not delete the input file.")
+ "but do not delete the input file.",
+ color=True,
+ )
group = parser.add_mutually_exclusive_group()
group.add_argument('--fast', action='store_true', help='compress faster')
group.add_argument('--best', action='store_true', help='compress better')
import argparse
import contextlib
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument('--cgi', action='store_true',
help='run as CGI server')
parser.add_argument('-b', '--bind', metavar='ADDRESS',
import argparse
import importlib
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument(
'object',
help="The object to be analysed. "
def main():
description = ('A simple command line interface for json module '
'to validate and pretty-print JSON objects.')
- parser = argparse.ArgumentParser(description=description)
+ parser = argparse.ArgumentParser(description=description, color=True)
parser.add_argument('infile', nargs='?',
help='a JSON file to be validated or pretty-printed',
default='-')
def _parse_args(args):
from argparse import ArgumentParser
- parser = ArgumentParser(description='map filename extensions to MIME types')
+ parser = ArgumentParser(
+ description='map filename extensions to MIME types', color=True
+ )
parser.add_argument(
'-e', '--extension',
action='store_true',
def main():
import argparse
- parser = argparse.ArgumentParser(usage="%(prog)s [-h] [-c command] (-m module | -p pid | pyfile) [args ...]",
- description=_usage,
- formatter_class=argparse.RawDescriptionHelpFormatter,
- allow_abbrev=False)
+ parser = argparse.ArgumentParser(
+ usage="%(prog)s [-h] [-c command] (-m module | -p pid | pyfile) [args ...]",
+ description=_usage,
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ allow_abbrev=False,
+ color=True,
+ )
# We need to maunally get the script from args, because the first positional
# arguments could be either the script we need to debug, or the argument
import argparse
import pprint
parser = argparse.ArgumentParser(
- description='display contents of the pickle files')
+ description='display contents of the pickle files',
+ color=True,
+ )
parser.add_argument(
'pickle_file',
nargs='+', help='the pickle file')
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
- description='disassemble one or more pickle files')
+ description='disassemble one or more pickle files',
+ color=True,
+ )
parser.add_argument(
'pickle_file',
nargs='+', help='the pickle file')
def _parse_args(args: list[str] | None):
import argparse
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument("args", nargs="*", choices=["nonaliased", "terse"])
parser.add_argument(
"--terse",
import argparse
description = 'A simple command-line interface for py_compile module.'
- parser = argparse.ArgumentParser(description=description)
+ parser = argparse.ArgumentParser(description=description, color=True)
parser.add_argument(
'-q', '--quiet',
action='store_true',
def _parse_args(arg_list: list[str] | None):
import argparse
parser = argparse.ArgumentParser(
- formatter_class=argparse.RawTextHelpFormatter)
+ formatter_class=argparse.RawTextHelpFormatter, color=True)
group = parser.add_mutually_exclusive_group()
group.add_argument(
"-c", "--choice", nargs="+",
def main(*args):
parser = ArgumentParser(
description="Python sqlite3 CLI",
+ color=True,
)
parser.add_argument(
"filename", type=str, default=":memory:", nargs="?",
import argparse
description = 'A simple command-line interface for tarfile module.'
- parser = argparse.ArgumentParser(description=description)
+ parser = argparse.ArgumentParser(description=description, color=True)
parser.add_argument('-v', '--verbose', action='store_true', default=False,
help='Verbose output')
parser.add_argument('--filter', metavar='<filtername>',
with self.subTest(flags=args):
self.invoke_ast(*args)
+ @support.force_not_colorized
def test_help_message(self):
for flag in ('-h', '--help', '--unknown'):
with self.subTest(flag=flag):
self.assertCLIFails(*args)
self.assertCmdFails(*args)
+ @support.force_not_colorized
def test_help(self):
stdout = self.run_cmd_ok('-h')
self.assertIn(b'usage:', stdout)
import unittest.mock
from platform import win32_edition
from test import support
-from test.support import os_helper
+from test.support import force_not_colorized, os_helper
try:
import _winapi
class CommandLineTest(unittest.TestCase):
+ @force_not_colorized
def test_parse_args(self):
args, help_text = mimetypes._parse_args("-h")
self.assertTrue(help_text.startswith("usage: "))
expect = self.text_normalize(expect)
self.assertListEqual(res.splitlines(), expect.splitlines())
+ @support.force_not_colorized
def test_unknown_flag(self):
stderr = io.StringIO()
with self.assertRaises(SystemExit):
self.invoke_platform(*flags)
obj.assert_called_once_with(aliased, terse)
+ @support.force_not_colorized
def test_help(self):
output = io.StringIO()
class CommandLineTest(unittest.TestCase):
+ @support.force_not_colorized
def test_parse_args(self):
args, help_text = random._parse_args(shlex.split("--choice a b c"))
self.assertEqual(args.choice, ["a", "b", "c"])
from sqlite3.__main__ import main as cli
from test.support.os_helper import TESTFN, unlink
-from test.support import captured_stdout, captured_stderr, captured_stdin
+from test.support import (
+ captured_stdout,
+ captured_stderr,
+ captured_stdin,
+ force_not_colorized,
+)
class CommandLineInterface(unittest.TestCase):
self.assertEqual(out, "")
return err
+ @force_not_colorized
def test_cli_help(self):
out = self.expect_success("-h")
self.assertIn("usage: ", out)
sys.exit(1)
# Parse the arguments and options
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument(dest='filename', nargs='?',
metavar='filename.py',
help='the file to tokenize; defaults to stdin')
def main():
import argparse
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument('--version', action='version', version='trace 2.0')
grp = parser.add_argument_group('Main options',
return parser
def _getMainArgParser(self, parent):
- parser = argparse.ArgumentParser(parents=[parent])
+ parser = argparse.ArgumentParser(parents=[parent], color=True)
parser.prog = self.progName
parser.print_help = self._print_help
return parser
def _getDiscoveryArgParser(self, parent):
- parser = argparse.ArgumentParser(parents=[parent])
+ parser = argparse.ArgumentParser(parents=[parent], color=True)
parser.prog = '%s discover' % self.progName
parser.epilog = ('For test discovery all test modules must be '
'importable from the top level directory of the '
import argparse
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
- description="Generate a UUID using the selected UUID function.")
+ description="Generate a UUID using the selected UUID function.",
+ color=True,
+ )
parser.add_argument("-u", "--uuid",
choices=uuid_funcs.keys(),
default="uuid4",
'created, you may wish to '
'activate it, e.g. by '
'sourcing an activate script '
- 'in its bin directory.')
+ 'in its bin directory.',
+ color=True,
+ )
parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
help='A directory to create the environment in.')
parser.add_argument('--system-site-packages', default=False,
def parse_args(arg_list: list[str] | None):
import argparse
- parser = argparse.ArgumentParser(description="Open URL in a web browser.")
+ parser = argparse.ArgumentParser(
+ description="Open URL in a web browser.", color=True,
+ )
parser.add_argument("url", help="URL to open")
group = parser.add_mutually_exclusive_group()
"""
import argparse
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(color=True)
parser.add_argument('--output', '-o', default=None,
help="The name of the output archive. "
"Required if SOURCE is an archive.")
import argparse
description = 'A simple command-line interface for zipfile module.'
- parser = argparse.ArgumentParser(description=description)
+ parser = argparse.ArgumentParser(description=description, color=True)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-l', '--list', metavar='<zipfile>',
help='Show listing of a zipfile')
--- /dev/null
+Add color to stdlib argparse CLIs. Patch by Hugo van Kemenade.