diff options
author | Georg Brandl <georg@python.org> | 2014-11-10 19:46:45 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-11-10 19:46:45 +0100 |
commit | 7069245134db629eddcfb3f00f21f8ea7f9c2d97 (patch) | |
tree | 9047d5837b43e96f7347e230a79fcae4730d5e1e | |
parent | e086160ee151b6517a62402edd3decf98f15c0cb (diff) | |
download | pygments-7069245134db629eddcfb3f00f21f8ea7f9c2d97.tar.gz |
Add a -v command line switch that shows the full traceback.
-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 c3f00fca..04b50075 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. """ @@ -207,7 +210,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 @@ -501,6 +504,18 @@ def main(args=sys.argv): return 0 except Exception: + if '-v' in opts: + 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() @@ -510,6 +525,8 @@ 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 return 0 diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index d02d088a..5d05f32a 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.assertIn('*** Error while highlighting:', 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') |