Skip to content

Commit 875d08e

Browse files
committed
Document and usage update
1 parent 1126142 commit 875d08e

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## About
22

3-
View **colored** diff in unified-diff format or **side-by-side** mode with
4-
**auto pager**. Requires Python (>= 2.5.0) and `less`.
3+
View **incremental**, **colored** diff in unified format or in **side by side**
4+
mode with **auto pager**. Requires python (>= 2.5.0) and `less`.
55

66
![Default](http://ymattw.github.com/cdiff/img/default.png)
7-
![Side-by-side](http://ymattw.github.com/cdiff/img/side-by-side.png)
7+
![Side by side](http://ymattw.github.com/cdiff/img/side-by-side.png)
88

99
## Installation
1010

@@ -18,14 +18,14 @@ whatever directory which is in your `$PATH`, for example, `$HOME/bin` is in my
1818
## Usage
1919

2020
Just give it a diff (patch) file or pipe a diff to it. Use option `-s` for
21-
side-by-side view, and option `-w <N>` to use text width other than default
21+
side-by-side view, and option `-w N` to set a text width other than default
2222
`80`. See examples below
2323

2424
View a diff (patch) file:
2525

26-
cdiff foo.patch # view colored udiff
27-
cdiff foo.patch -s # side-by-side
28-
cdiff foo.patch -s -w 90 # use text width 90 other than default 80
26+
cdiff foo.patch # view incremental, colored udiff
27+
cdiff foo.patch -s # view in side by side mode
28+
cdiff foo.patch -s -w 90 # use text width 90 other than default 80
2929

3030
Read diff from svn:
3131

@@ -46,4 +46,4 @@ Redirect output to another patch file is safe:
4646
## Known issue
4747

4848
- Only support unified format for input diff
49-
- Side-by-side mode has alignment problem for wide chars
49+
- Side by side mode has alignment problem for wide chars

src/cdiff.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# -*- coding: utf-8 -*-
33

44
"""
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.
77
88
See demo at homepage: https://github.com/ymattw/cdiff
99
"""
@@ -13,7 +13,7 @@
1313
if sys.hexversion < 0x02050000:
1414
sys.stderr.write("ERROR: requires python >= 2.5.0\n")
1515
sys.exit(1)
16-
_is_py3 = sys.hexversion >= 0x03000000
16+
IS_PY3 = sys.hexversion >= 0x03000000
1717

1818
import os
1919
import re
@@ -475,27 +475,26 @@ def markup_to_pager(stream):
475475
import optparse
476476
import subprocess
477477

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''')
480482

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)
485484
parser.add_option('-s', '--side-by-side', action='store_true',
486485
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')
489488
opts, args = parser.parse_args()
490489

491490
if len(args) >= 1:
492-
if _is_py3:
491+
if IS_PY3:
493492
# Python3 needs the newline='' to keep '\r' (DOS format)
494493
diff_hdl = open(args[0], mode='rt', newline='')
495494
else:
496495
diff_hdl = open(args[0], mode='rt')
497496
elif sys.stdin.isatty():
498-
sys.stderr.write('Try --help option for usage\n')
497+
parser.print_help()
499498
sys.exit(1)
500499
else:
501500
diff_hdl = sys.stdin

0 commit comments

Comments
 (0)