Browse Source

Document and usage update

Matthew Wang 11 years ago
parent
commit
875d08ecb4
2 changed files with 20 additions and 21 deletions
  1. 8
    8
      README.md
  2. 12
    13
      src/cdiff.py

+ 8
- 8
README.md View File

@@ -1,10 +1,10 @@
1 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 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 9
 ## Installation
10 10
 
@@ -18,14 +18,14 @@ whatever directory which is in your `$PATH`, for example, `$HOME/bin` is in my
18 18
 ## Usage
19 19
     
20 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 22
 `80`.  See examples below
23 23
 
24 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 30
 Read diff from svn:
31 31
 
@@ -46,4 +46,4 @@ Redirect output to another patch file is safe:
46 46
 ## Known issue
47 47
 
48 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 View File

@@ -2,8 +2,8 @@
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,7 +13,7 @@ import sys
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 @@ if __name__ == '__main__':
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