diff options
author | Georg Brandl <georg@python.org> | 2014-11-10 20:10:45 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-11-10 20:10:45 +0100 |
commit | e460ebf07d887385aed294fee486f67b9718a7d1 (patch) | |
tree | 40f5fa819e52a14d984cc21529deffb67ef09c3b | |
parent | 1b0b3bd0c52d997f707201fbaf973b9f49c5dcb8 (diff) | |
parent | 7069245134db629eddcfb3f00f21f8ea7f9c2d97 (diff) | |
download | pygments-e460ebf07d887385aed294fee486f67b9718a7d1.tar.gz |
merge with stable
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | pygments/cmdline.py | 21 | ||||
-rw-r--r-- | tests/test_cmdline.py | 8 |
3 files changed, 29 insertions, 4 deletions
@@ -2,9 +2,9 @@ Pygments changelog ================== Issue numbers refer to the tracker at -<http://bitbucket.org/birkenfeld/pygments-main/issues>, +<https://bitbucket.org/birkenfeld/pygments-main/issues>, pull request numbers to the requests at -<http://bitbucket.org/birkenfeld/pygments-main/pull-requests/merged>. +<https://bitbucket.org/birkenfeld/pygments-main/pull-requests/merged>. Version 2.0.1 diff --git a/pygments/cmdline.py b/pygments/cmdline.py index 20e87c36..53e858b5 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -30,7 +30,7 @@ from pygments.styles import get_all_styles, get_style_by_name USAGE = """\ Usage: %s [-l <lexer> | -g] [-F <filter>[:<options>]] [-f <formatter>] - [-O <options>] [-P <option=value>] [-s] [-o <outfile>] [<infile>] + [-O <options>] [-P <option=value>] [-s] [-v] [-o <outfile>] [<infile>] %s -S <style> -f <formatter> [-a <arg>] [-O <options>] [-P <option=value>] %s -L [<which> ...] @@ -90,6 +90,9 @@ waiting to process the entire file. This only works for stdin, and is intended for streaming input such as you get from 'tail -f'. Example usage: "tail -f sql.log | pygmentize -s -l sql" +The -v option prints a detailed traceback on unhandled exceptions, +which is useful for debugging and bug reports. + The -h option prints this help. The -V option prints the package version. """ @@ -496,7 +499,7 @@ def main(args=sys.argv): usage = USAGE % ((args[0],) * 6) try: - popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:hVHgs") + popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:vhVHgs") except getopt.GetoptError: print(usage, file=sys.stderr) return 2 @@ -504,6 +507,18 @@ def main(args=sys.argv): try: return main_inner(popts, args, usage) except Exception: + if '-v' in dict(popts): + print(file=sys.stderr) + print('*' * 65, file=sys.stderr) + print('An unhandled exception occurred while highlighting.', + file=sys.stderr) + print('Please report the whole traceback to the issue tracker at', + file=sys.stderr) + print('<https://bitbucket.org/birkenfeld/pygments-main/issues>.', + file=sys.stderr) + print('*' * 65, file=sys.stderr) + print(file=sys.stderr) + raise import traceback info = traceback.format_exception(*sys.exc_info()) msg = info[-1].strip() @@ -513,4 +528,6 @@ def main(args=sys.argv): print(file=sys.stderr) print('*** Error while highlighting:', file=sys.stderr) print(msg, file=sys.stderr) + print('*** If this is a bug you want to report, please rerun with -v.', + file=sys.stderr) return 1 diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index d6a149ae..d2a9d702 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -175,3 +175,11 @@ class CmdLineTest(unittest.TestCase): c, e = run_cmdline_with_closed_stdout('-lpython', TESTFILE) self.assertEqual(c, 1) self.assertTrue('*** Error while highlighting:' in e) + + # same with -v: should reraise the exception + try: + run_cmdline_with_closed_stdout('-lpython', '-v', TESTFILE) + except Exception: + pass + else: + self.fail('exception not reraised') |