@@ -11,58 +11,22 @@ import Distribution.Fields.Field (FieldName)
11
11
import Distribution.Utils.ShortText (fromShortText )
12
12
13
13
import qualified Distribution.Compat.Lens as L
14
- import qualified Distribution.Compat.CharParsing as C
15
14
import qualified Distribution.FieldGrammar as C
16
- import qualified Distribution.Parsec as C
17
15
import qualified Distribution.Pretty as C
18
- import qualified Text.PrettyPrint as PP
19
16
20
17
import HaskellCI.OptionsGrammar
21
- import HaskellCI.Config.Empty (runEG )
22
-
23
- data ShowDiffOptions = ShowAllOptions | ShowChangedOptions
24
- deriving (Eq , Show , Generic , Binary )
25
-
26
- instance C. Parsec ShowDiffOptions where
27
- parsec = ShowAllOptions <$ C. string " all"
28
- <|> ShowChangedOptions <$ C. string " changed"
29
-
30
- instance C. Pretty ShowDiffOptions where
31
- pretty ShowAllOptions = PP. text " all"
32
- pretty ShowChangedOptions = PP. text " changed"
33
-
34
- data DiffConfig = DiffConfig
35
- { diffShowOptions :: ShowDiffOptions
36
- , diffShowOld :: Bool
37
- } deriving (Show , Generic , Binary )
38
-
39
- diffConfigGrammar
40
- :: ( OptionsGrammar c g
41
- , Applicative (g DiffConfig )
42
- , c (Identity ShowDiffOptions ))
43
- => g DiffConfig DiffConfig
44
- diffConfigGrammar = DiffConfig
45
- <$> C. optionalFieldDef " diff-show-options" (field @ " diffShowOptions" ) ShowChangedOptions
46
- ^^^ help " Which fields to show"
47
- <*> C. booleanFieldDef " diff-show-old" (field @ " diffShowOld" ) False
48
- ^^^ help " Show the old values for every field"
49
-
50
- defaultDiffConfig :: DiffConfig
51
- defaultDiffConfig = case runEG diffConfigGrammar of
52
- Left xs -> error $ " Required fields: " ++ show xs
53
- Right x -> x
54
18
55
19
newtype DiffOptions s a =
56
- DiffOptions { runDiffOptions :: (s , s ) -> DiffConfig -> [String ] }
20
+ DiffOptions { runDiffOptions :: (s , s ) -> [String ] }
57
21
deriving Functor
58
22
59
23
instance Applicative (DiffOptions s ) where
60
- pure _ = DiffOptions $ \ _ _ -> []
24
+ pure _ = DiffOptions $ \ _ -> []
61
25
DiffOptions f <*> DiffOptions x = DiffOptions (f <> x)
62
26
63
- diffConfigs :: DiffConfig -> DiffOptions a a -> a -> a -> [String ]
64
- diffConfigs config grammar oldVal newVal =
65
- runDiffOptions grammar (oldVal, newVal) config
27
+ diffConfigs :: DiffOptions a a -> a -> a -> [String ]
28
+ diffConfigs grammar oldVal newVal =
29
+ runDiffOptions grammar (oldVal, newVal)
66
30
67
31
diffUnique
68
32
:: Eq b
@@ -71,25 +35,20 @@ diffUnique
71
35
-> FieldName
72
36
-> L. ALens' s a
73
37
-> (s , s )
74
- -> DiffConfig
75
38
-> [String ]
76
- diffUnique project render fn lens (diffOld, diffNew) opts =
77
- case diffShowOptions opts of
78
- ShowChangedOptions | notEqual -> []
79
- ShowAllOptions | notEqual -> newLine
80
- _ -> oldLine ++ newLine
39
+ diffUnique project render fn lens (diffOld, diffNew)
40
+ | notEqual =
41
+ [ " -" ++ fromUTF8BS fn ++ " : " ++ render oldValue
42
+ , " +" ++ fromUTF8BS fn ++ " : " ++ render newValue
43
+ , " "
44
+ ]
45
+
46
+ | otherwise = []
81
47
where
82
- notEqual = project oldValue = = project newValue
48
+ notEqual = project oldValue / = project newValue
83
49
oldValue = L. aview lens $ diffOld
84
50
newValue = L. aview lens $ diffNew
85
51
86
- oldLine
87
- | diffShowOld opts = [" -- " ++ fromUTF8BS fn ++ " : " ++ render oldValue]
88
- | otherwise = []
89
-
90
- newLine = [ fromUTF8BS fn ++ " : " ++ render newValue, " " ]
91
-
92
-
93
52
instance C. FieldGrammar C. Pretty DiffOptions where
94
53
blurFieldGrammar lens (DiffOptions diff) =
95
54
DiffOptions $ diff . bimap (L. aview lens) (L. aview lens)
@@ -130,7 +89,7 @@ instance C.FieldGrammar C.Pretty DiffOptions where
130
89
instance OptionsGrammar C. Pretty DiffOptions where
131
90
metahelp _ = help
132
91
133
- help h (DiffOptions xs) = DiffOptions $ \ vals config ->
134
- case xs vals config of
92
+ help h (DiffOptions xs) = DiffOptions $ \ vals ->
93
+ case xs vals of
135
94
[] -> []
136
95
diffString -> (" -- " ++ h) : diffString
0 commit comments