1
+ {-# LANGUAGE DeriveDataTypeable #-}
2
+ {- |
3
+ Module : Diffr.Util
4
+ Description : Utility functions and configuration options
5
+ Since : 0.1
6
+ Authors : William Martin, Jakub Kozlowski
7
+ License : This file is part of diffr-h.
8
+
9
+ diffr-h is free software: you can redistribute it and/or modify
10
+ it under the terms of the GNU General Public License as published by
11
+ the Free Software Foundation, either version 3 of the License, or
12
+ (at your option) any later version.
13
+
14
+ diffr-h is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ GNU General Public License for more details.
18
+ You should have received a copy of the GNU General Public License
19
+ along with diffr-h. If not, see <http://www.gnu.org/licenses/>.
20
+ -}
21
+ module Diffr.Util (
22
+ DConfig (.. )
23
+ , diffrModes
24
+ ) where
25
+
26
+ import System.Console.CmdArgs
27
+
28
+ {-| Static values -}
29
+ _PROGRAM_NAME, _PROGRAM_VERSION,
30
+ _PROGRAM_INFO , _PROGRAM_ABOUT , _COPYRIGHT :: String
31
+ _PROGRAM_NAME = " diffr"
32
+ _PROGRAM_VERSION = " 0.1"
33
+ _PROGRAM_INFO = _PROGRAM_NAME ++ " version " ++ _PROGRAM_VERSION
34
+ _PROGRAM_ABOUT = unwords [
35
+ " An intelligent diff/patch tool"
36
+ , " that knows how to copy and move,"
37
+ , " has an 'r' at the end of its name"
38
+ , " and is written in Haskell." ]
39
+ _COPYRIGHT = " (C) diffr 2013"
40
+
41
+ ------------------------------------------------
42
+
43
+ {-| Configuration for running diffr's commands -}
44
+ data DConfig =
45
+
46
+ -- | Configuration for running diff command
47
+ Diff { -- | Path to the 'base' file we will diff against
48
+ baseFile :: FilePath
49
+
50
+ -- | Path to the 'new' file we will compare to 'base' file
51
+ , newFile :: FilePath
52
+
53
+ -- | Path to the output file where to write the diff file
54
+ , dOutFile :: Maybe FilePath
55
+ }
56
+
57
+ -- | Configuration for running patch command
58
+ | Patch { -- | Path to the 'original' file we will apply patch to
59
+ originalFile :: FilePath
60
+
61
+ -- | Path to the 'patch' file we will apply to 'originalFile'
62
+ , patchFile :: FilePath
63
+
64
+ -- | Path to the output file where to write the patched file
65
+ , pOutFile :: Maybe FilePath
66
+ } deriving (Show , Data , Typeable )
67
+
68
+ {-| Annotate the 'Diff' configuration -}
69
+ diff :: DConfig
70
+ diff = Diff
71
+ { baseFile = def &= argPos 0
72
+ &= typ " BASEFILE"
73
+ , newFile = def &= argPos 1
74
+ &= typ " NEWFILE"
75
+ , dOutFile = def &= help " path to the output file"
76
+ &= name " output-file" &= typFile
77
+ }
78
+
79
+ {-| Annotate the 'Patch' configuration -}
80
+ patch :: DConfig
81
+ patch = Patch
82
+ { originalFile = def &= argPos 0
83
+ &= typ " ORIGINALFILE"
84
+ , patchFile = def &= argPos 1
85
+ &= typ " PATCHFILE"
86
+ , pOutFile = def &= help " Path to the output file where to write the patched file"
87
+ &= name " output-file"
88
+ &= typFile
89
+ }
90
+
91
+ {-| Available commands -}
92
+ diffrModes :: Mode (CmdArgs DConfig )
93
+ diffrModes = cmdArgsMode $ modes [diff, patch]
94
+ &= versionArg [explicit, name " version" , name " v" , summary _PROGRAM_INFO]
95
+ &= summary (_PROGRAM_INFO ++ " , " ++ _COPYRIGHT)
96
+ &= help _PROGRAM_ABOUT
97
+ &= helpArg [explicit, name " help" , name " h" ]
98
+ &= program _PROGRAM_NAME
99
+
0 commit comments