diff --git a/ghcup-0.0.2.yaml b/ghcup-0.0.2.yaml index cbf278a..873de2f 100644 --- a/ghcup-0.0.2.yaml +++ b/ghcup-0.0.2.yaml @@ -1,3 +1,4 @@ +# !!! if you use RegexDir, then the version must be bumped !!! --- toolRequirements: GHC: diff --git a/lib/GHCup/Types/JSON.hs b/lib/GHCup/Types/JSON.hs index 1320c5e..c271a08 100644 --- a/lib/GHCup/Types/JSON.hs +++ b/lib/GHCup/Types/JSON.hs @@ -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