Browse Source

Merge branch 'CDIFF_OPTIONS'

Matthew Wang 7 years ago
parent
commit
2523f26b49
3 changed files with 23 additions and 3 deletions
  1. 11
    1
      README.rst
  2. 7
    2
      cdiff.py
  3. 5
    0
      tests/test_cdiff.py

+ 11
- 1
README.rst View File

97
 
97
 
98
       Note:
98
       Note:
99
         Option parser will stop on first unknown option and pass them down to
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
 Read diff from local modification in a *Git/Mercurial/Svn* workspace (output
104
 Read diff from local modification in a *Git/Mercurial/Svn* workspace (output
103
 from e.g. ``git diff``, ``svn diff``):
105
 from e.g. ``git diff``, ``svn diff``):
126
     cdiff -ls -w90              # set text width 90 as well
128
     cdiff -ls -w90              # set text width 90 as well
127
     cdiff -ls file1 dir2        # see log with changes of given files/dirs only
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
 If you feel more comfortable with a command such as ``git cdiff`` to trigger
139
 If you feel more comfortable with a command such as ``git cdiff`` to trigger
130
 the cdiff command, you may symlink the executable to one named ``git-cdiff``
140
 the cdiff command, you may symlink the executable to one named ``git-cdiff``
131
 as follows:
141
 as follows:

+ 7
- 2
cdiff.py View File

755
     # Hack: use OptionGroup text for extra help message after option list
755
     # Hack: use OptionGroup text for extra help message after option list
756
     option_group = OptionGroup(
756
     option_group = OptionGroup(
757
         parser, "Note", ("Option parser will stop on first unknown option "
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
     parser.add_option_group(option_group)
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
     if opts.log:
768
     if opts.log:
764
         diff_hdl = revision_control_log(args)
769
         diff_hdl = revision_control_log(args)

+ 5
- 0
tests/test_cdiff.py View File

737
                'cd %s; git add foo; git commit foo -m update' % self._ws]
737
                'cd %s; git add foo; git commit foo -m update' % self._ws]
738
         subprocess.call(cmd, stdout=subprocess.PIPE)
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
     def test_read_diff(self):
745
     def test_read_diff(self):
741
         sys.argv = sys.argv[:1]
746
         sys.argv = sys.argv[:1]
742
         self._change_file('read_diff')
747
         self._change_file('read_diff')