Bladeren bron

Fix #59 with env variable CDIFF_OPTIONS

Matthew Wang 8 jaren geleden
bovenliggende
commit
f3fe271a35
2 gewijzigde bestanden met toevoegingen van 18 en 3 verwijderingen
  1. 11
    1
      README.rst
  2. 7
    2
      cdiff.py

+ 11
- 1
README.rst Bestand weergeven

@@ -97,7 +97,9 @@ Type ``cdiff -h`` to show usage::
97 97
 
98 98
       Note:
99 99
         Option parser will stop on first unknown option and pass them down to
100
-        underneath revision control
100
+        underneath revision control. Environment variable CDIFF_OPTIONS may be
101
+        used to specify default options that will be placed at the beginning
102
+        of the argument list.
101 103
 
102 104
 Read diff from local modification in a *Git/Mercurial/Svn* workspace (output
103 105
 from e.g. ``git diff``, ``svn diff``):
@@ -126,6 +128,14 @@ Read log with changes in a *Git/Mercurial/Svn* workspace (output from e.g.
126 128
     cdiff -ls -w90              # set text width 90 as well
127 129
     cdiff -ls file1 dir2        # see log with changes of given files/dirs only
128 130
 
131
+Environment variable ``CDIFF_OPTIONS`` may be used to specify default options
132
+that will be placed at the beginning of the argument list, for example:
133
+
134
+.. code-block:: bash
135
+
136
+    export CDIFF_OPTIONS='-s -w0'
137
+    cdiff foo                   # equivalent to "cdiff -s -w0 foo"
138
+
129 139
 If you feel more comfortable with a command such as ``git cdiff`` to trigger
130 140
 the cdiff command, you may symlink the executable to one named ``git-cdiff``
131 141
 as follows:

+ 7
- 2
cdiff.py Bestand weergeven

@@ -755,10 +755,15 @@ def main():
755 755
     # Hack: use OptionGroup text for extra help message after option list
756 756
     option_group = OptionGroup(
757 757
         parser, "Note", ("Option parser will stop on first unknown option "
758
-                         "and pass them down to underneath revision control"))
758
+                         "and pass them down to underneath revision control. "
759
+                         "Environment variable CDIFF_OPTIONS may be used to "
760
+                         "specify default options that will be placed at the "
761
+                         "beginning of the argument list."))
759 762
     parser.add_option_group(option_group)
760 763
 
761
-    opts, args = parser.parse_args()
764
+    # Place possible options defined in CDIFF_OPTIONS at the beginning of argv
765
+    cdiff_opts = [x for x in os.getenv('CDIFF_OPTIONS', '').split(' ') if x]
766
+    opts, args = parser.parse_args(cdiff_opts + sys.argv[1:])
762 767
 
763 768
     if opts.log:
764 769
         diff_hdl = revision_control_log(args)