@@ -11,58 +11,22 @@ import Distribution.Fields.Field (FieldName)
1111import Distribution.Utils.ShortText (fromShortText )
1212
1313import qualified Distribution.Compat.Lens as L
14- import qualified Distribution.Compat.CharParsing as C
1514import qualified Distribution.FieldGrammar as C
16- import qualified Distribution.Parsec as C
1715import qualified Distribution.Pretty as C
18- import qualified Text.PrettyPrint as PP
1916
2017import 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
5418
5519newtype DiffOptions s a =
56- DiffOptions { runDiffOptions :: (s , s ) -> DiffConfig -> [String ] }
20+ DiffOptions { runDiffOptions :: (s , s ) -> [String ] }
5721 deriving Functor
5822
5923instance Applicative (DiffOptions s ) where
60- pure _ = DiffOptions $ \ _ _ -> []
24+ pure _ = DiffOptions $ \ _ -> []
6125 DiffOptions f <*> DiffOptions x = DiffOptions (f <> x)
6226
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)
6630
6731diffUnique
6832 :: Eq b
@@ -71,25 +35,20 @@ diffUnique
7135 -> FieldName
7236 -> L. ALens' s a
7337 -> (s , s )
74- -> DiffConfig
7538 -> [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 = []
8147 where
82- notEqual = project oldValue = = project newValue
48+ notEqual = project oldValue / = project newValue
8349 oldValue = L. aview lens $ diffOld
8450 newValue = L. aview lens $ diffNew
8551
86- oldLine
87- | diffShowOld opts = [" -- " ++ fromUTF8BS fn ++ " : " ++ render oldValue]
88- | otherwise = []
89-
90- newLine = [ fromUTF8BS fn ++ " : " ++ render newValue, " " ]
91-
92-
9352instance C. FieldGrammar C. Pretty DiffOptions where
9453 blurFieldGrammar lens (DiffOptions diff) =
9554 DiffOptions $ diff . bimap (L. aview lens) (L. aview lens)
@@ -130,7 +89,7 @@ instance C.FieldGrammar C.Pretty DiffOptions where
13089instance OptionsGrammar C. Pretty DiffOptions where
13190 metahelp _ = help
13291
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
13594 [] -> []
13695 diffString -> (" -- " ++ h) : diffString
0 commit comments