Make TarDir backwardscompat

This commit is contained in:
Julian Ospald 2020-08-10 22:22:48 +02:00
parent 27b2d2ac7d
commit dac64f5718
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 14 additions and 1 deletions

View File

@ -1,3 +1,4 @@
# !!! if you use RegexDir, then the version must be bumped !!!
---
toolRequirements:
GHC:

View File

@ -24,6 +24,7 @@ module GHCup.Types.JSON where
import GHCup.Types
import GHCup.Utils.Prelude
import Control.Applicative ( (<|>) )
import Data.Aeson
import Data.Aeson.TH
import Data.Aeson.Types
@ -195,5 +196,16 @@ instance FromJSON (Path Rel) where
Left e -> fail $ "Failure in HPath Rel (FromJSON)" <> show e
deriveJSON defaultOptions{ sumEncoding = ObjectWithSingleField } ''TarDir
instance ToJSON TarDir where
toJSON (RealDir p) = toJSON p
toJSON (RegexDir r) = object ["RegexDir" .= r]
instance FromJSON TarDir where
parseJSON v = realDir v <|> regexDir v
where
realDir = withText "TarDir" $ \t -> do
fp <- parseJSON (String t)
pure (RealDir fp)
regexDir = withObject "TarDir" $ \o -> do
r <- o .: "RegexDir"
pure $ RegexDir r