Ver código fonte

Merge branch 'CDIFF_OPTIONS'

Matthew Wang 8 anos atrás
pai
commit
2523f26b49
3 arquivos alterados com 23 adições e 3 exclusões
  1. 11
    1
      README.rst
  2. 7
    2
      cdiff.py
  3. 5
    0
      tests/test_cdiff.py

+ 11
- 1
README.rst Ver arquivo

@@ -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 Ver arquivo

@@ -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)

+ 5
- 0
tests/test_cdiff.py Ver arquivo

@@ -737,6 +737,11 @@ class MainTest(unittest.TestCase):
737 737
                'cd %s; git add foo; git commit foo -m update' % self._ws]
738 738
         subprocess.call(cmd, stdout=subprocess.PIPE)
739 739
 
740
+    def test_preset_options(self):
741
+        os.environ['CDIFF_OPTIONS'] = '--help'
742
+        self.assertRaises(SystemExit, cdiff.main)
743
+        os.environ.pop('CDIFF_OPTIONS', None)
744
+
740 745
     def test_read_diff(self):
741 746
         sys.argv = sys.argv[:1]
742 747
         self._change_file('read_diff')