Improve backwards-compat for config (manual FromJson)
parent
8f1e366f9c
commit
3957272c10
|
@ -107,6 +107,7 @@ library {
|
|||
, semigroups >=0.18.2 && <0.19
|
||||
, cmdargs >=0.10.14 && <0.11
|
||||
, czipwith >=1.0.0.0 && <1.1
|
||||
, unordered-containers >=0.2.7 && <0.3
|
||||
}
|
||||
default-extensions: {
|
||||
CPP
|
||||
|
@ -167,6 +168,7 @@ executable brittany
|
|||
, semigroups
|
||||
, cmdargs
|
||||
, czipwith
|
||||
, unordered-containers
|
||||
, hspec >=2.4.1 && <2.5
|
||||
, filepath >=1.4.1.0 && <1.5
|
||||
, ghc-boot-th >=8.0.1 && <8.1
|
||||
|
@ -245,6 +247,7 @@ test-suite unittests
|
|||
, semigroups
|
||||
, cmdargs
|
||||
, czipwith
|
||||
, unordered-containers
|
||||
, hspec >=2.4.1 && <2.5
|
||||
}
|
||||
ghc-options: -Wall
|
||||
|
@ -318,6 +321,7 @@ test-suite littests
|
|||
, semigroups
|
||||
, cmdargs
|
||||
, czipwith
|
||||
, unordered-containers
|
||||
, hspec >=2.4.1 && <2.5
|
||||
, parsec >=3.1.11 && <3.2
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ where
|
|||
|
||||
import Data.Yaml
|
||||
import qualified Data.Aeson.Types as Aeson
|
||||
import qualified Data.HashMap.Lazy as HML
|
||||
import GHC.Generics
|
||||
|
||||
import Data.Data ( Data )
|
||||
|
@ -219,10 +220,26 @@ makeToJSONOption(CPreProcessorConfig)
|
|||
makeToJSONMaybe(CPreProcessorConfig)
|
||||
|
||||
makeFromJSONOption(CConfig)
|
||||
makeFromJSONMaybe(CConfig)
|
||||
makeToJSONOption(CConfig)
|
||||
makeToJSONMaybe(CConfig)
|
||||
|
||||
-- This custom instance ensures the "omitNothingFields" behaviour not only for
|
||||
-- leafs, but for nodes of the config as well. This way e.g. "{}" is valid
|
||||
-- config file content.
|
||||
instance FromJSON (CConfig Maybe) where
|
||||
parseJSON (Object v) = Config
|
||||
<$> v .:? Text.pack "conf_version"
|
||||
<*> v .:?= Text.pack "conf_debug"
|
||||
<*> v .:?= Text.pack "conf_layout"
|
||||
<*> v .:?= Text.pack "conf_errorHandling"
|
||||
<*> v .:?= Text.pack "conf_forward"
|
||||
<*> v .:?= Text.pack "conf_preprocessor"
|
||||
parseJSON invalid = Aeson.typeMismatch "Config" invalid
|
||||
|
||||
-- Pretends that the value is {} when the key is not present.
|
||||
(.:?=) :: FromJSON a => Object -> Text -> Parser a
|
||||
o .:?= k = o .:? k >>= maybe (parseJSON (Object HML.empty)) pure
|
||||
|
||||
data IndentPolicy = IndentPolicyLeft -- never create a new indentation at more
|
||||
-- than old indentation + amount
|
||||
| IndentPolicyFree -- can create new indentations whereever
|
||||
|
|
Loading…
Reference in New Issue