瀏覽代碼

Document and usage update

Matthew Wang 11 年之前
父節點
當前提交
875d08ecb4
共有 2 個檔案被更改,包括 20 行新增21 行删除
  1. 8
    8
      README.md
  2. 12
    13
      src/cdiff.py

+ 8
- 8
README.md 查看文件

1
 ## About
1
 ## About
2
 
2
 
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`.
5
 
5
 
6
 ![Default](http://ymattw.github.com/cdiff/img/default.png)
6
 ![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)
8
 
8
 
9
 ## Installation
9
 ## Installation
10
 
10
 
18
 ## Usage
18
 ## Usage
19
     
19
     
20
 Just give it a diff (patch) file or pipe a diff to it.  Use option `-s` for
20
 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
22
 `80`.  See examples below
22
 `80`.  See examples below
23
 
23
 
24
 View a diff (patch) file:
24
 View a diff (patch) file:
25
 
25
 
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
29
     
29
     
30
 Read diff from svn:
30
 Read diff from svn:
31
 
31
 
46
 ## Known issue
46
 ## Known issue
47
 
47
 
48
 - Only support unified format for input diff
48
 - 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

+ 12
- 13
src/cdiff.py 查看文件

2
 # -*- coding: utf-8 -*-
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
 See demo at homepage: https://github.com/ymattw/cdiff
8
 See demo at homepage: https://github.com/ymattw/cdiff
9
 """
9
 """
13
 if sys.hexversion < 0x02050000:
13
 if sys.hexversion < 0x02050000:
14
     sys.stderr.write("ERROR: requires python >= 2.5.0\n")
14
     sys.stderr.write("ERROR: requires python >= 2.5.0\n")
15
     sys.exit(1)
15
     sys.exit(1)
16
-_is_py3 = sys.hexversion >= 0x03000000
16
+IS_PY3 = sys.hexversion >= 0x03000000
17
 
17
 
18
 import os
18
 import os
19
 import re
19
 import re
475
     import optparse
475
     import optparse
476
     import subprocess
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
     parser.add_option('-s', '--side-by-side', action='store_true',
484
     parser.add_option('-s', '--side-by-side', action='store_true',
486
             help=('show in side-by-side mode'))
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
     opts, args = parser.parse_args()
488
     opts, args = parser.parse_args()
490
 
489
 
491
     if len(args) >= 1:
490
     if len(args) >= 1:
492
-        if _is_py3:
491
+        if IS_PY3:
493
             # Python3 needs the newline='' to keep '\r' (DOS format)
492
             # Python3 needs the newline='' to keep '\r' (DOS format)
494
             diff_hdl = open(args[0], mode='rt', newline='')
493
             diff_hdl = open(args[0], mode='rt', newline='')
495
         else:
494
         else:
496
             diff_hdl = open(args[0], mode='rt')
495
             diff_hdl = open(args[0], mode='rt')
497
     elif sys.stdin.isatty():
496
     elif sys.stdin.isatty():
498
-        sys.stderr.write('Try --help option for usage\n')
497
+        parser.print_help()
499
         sys.exit(1)
498
         sys.exit(1)
500
     else:
499
     else:
501
         diff_hdl = sys.stdin
500
         diff_hdl = sys.stdin