|
2 | 2 | # -*- coding: utf-8 -*-
|
3 | 3 |
|
4 | 4 | """
|
5 |
| -View colored diff in unified-diff format or side-by-side mode with auto pager. |
6 |
| -Requires Python (>= 2.5.0) and less. |
| 5 | +View incremental, colored diff in unified format or in side by side mode with |
| 6 | +auto pager. Requires Python (>= 2.5.0) and less. |
7 | 7 |
|
8 | 8 | See demo at homepage: https://github.com/ymattw/cdiff
|
9 | 9 | """
|
|
13 | 13 | if sys.hexversion < 0x02050000:
|
14 | 14 | sys.stderr.write("ERROR: requires python >= 2.5.0\n")
|
15 | 15 | sys.exit(1)
|
16 |
| -_is_py3 = sys.hexversion >= 0x03000000 |
| 16 | +IS_PY3 = sys.hexversion >= 0x03000000 |
17 | 17 |
|
18 | 18 | import os
|
19 | 19 | import re
|
@@ -475,27 +475,26 @@ def markup_to_pager(stream):
|
475 | 475 | import optparse
|
476 | 476 | import subprocess
|
477 | 477 |
|
478 |
| - usage = ''' |
479 |
| - %(prog)s [options] [diff] |
| 478 | + usage = '''%s [options] [diff]''' % os.path.basename(sys.argv[0]) |
| 479 | + description= ('''View incremental, colored diff in unified format or ''' |
| 480 | + '''in side by side mode with auto pager, read stdin if ''' |
| 481 | + '''diff (patch) file is not given''') |
480 | 482 |
|
481 |
| - View diff (patch) file if given, otherwise read stdin''' % \ |
482 |
| - {'prog': os.path.basename(sys.argv[0])} |
483 |
| - |
484 |
| - parser = optparse.OptionParser(usage) |
| 483 | + parser = optparse.OptionParser(usage=usage, description=description) |
485 | 484 | parser.add_option('-s', '--side-by-side', action='store_true',
|
486 | 485 | help=('show in side-by-side mode'))
|
487 |
| - parser.add_option('-w', '--width', type='int', default=80, |
488 |
| - help='set line width (side-by-side mode only), default is 80') |
| 486 | + parser.add_option('-w', '--width', type='int', default=80, metavar='N', |
| 487 | + help='set text width (side-by-side mode only), default is 80') |
489 | 488 | opts, args = parser.parse_args()
|
490 | 489 |
|
491 | 490 | if len(args) >= 1:
|
492 |
| - if _is_py3: |
| 491 | + if IS_PY3: |
493 | 492 | # Python3 needs the newline='' to keep '\r' (DOS format)
|
494 | 493 | diff_hdl = open(args[0], mode='rt', newline='')
|
495 | 494 | else:
|
496 | 495 | diff_hdl = open(args[0], mode='rt')
|
497 | 496 | elif sys.stdin.isatty():
|
498 |
| - sys.stderr.write('Try --help option for usage\n') |
| 497 | + parser.print_help() |
499 | 498 | sys.exit(1)
|
500 | 499 | else:
|
501 | 500 | diff_hdl = sys.stdin
|
|
0 commit comments