{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE ExplicitNamespaces #-}
module Data.ConfigFile.B9Extras
( addSectionCP,
setShowCP,
setCP,
readCP,
mergeCP,
toStringCP,
sectionsCP,
emptyCP,
type CPGet,
type CPOptionSpec,
type CPSectionSpec,
type CPDocument,
CPError (),
readCPDocument,
CPReadException (..),
)
where
import Control.Exception
import Control.Monad.Except
import Data.ConfigFile
import Data.Typeable
import System.IO.B9Extras
type CPDocument = ConfigParser
type CPSectionSpec = SectionSpec
type CPOptionSpec = OptionSpec
setShowCP ::
(Show a, MonadError CPError m) =>
CPDocument ->
CPSectionSpec ->
CPOptionSpec ->
a ->
m CPDocument
setShowCP = setshow
setCP ::
(MonadError CPError m) =>
CPDocument ->
CPSectionSpec ->
CPOptionSpec ->
String ->
m CPDocument
setCP = set
readCP ::
(CPGet a, MonadError CPError m) =>
CPDocument ->
CPSectionSpec ->
CPOptionSpec ->
m a
readCP = get
type CPGet a = Get_C a
addSectionCP ::
MonadError CPError m => CPDocument -> CPSectionSpec -> m CPDocument
addSectionCP = add_section
mergeCP :: CPDocument -> CPDocument -> CPDocument
mergeCP = merge
toStringCP :: CPDocument -> String
toStringCP = to_string
sectionsCP :: CPDocument -> [SectionSpec]
sectionsCP = sections
readCPDocument :: MonadIO m => SystemPath -> m CPDocument
readCPDocument cfgFile' = do
cfgFilePath <- resolve cfgFile'
liftIO $ do
res <- readfile emptyCP cfgFilePath
case res of
Left e -> throwIO (CPReadException cfgFilePath e)
Right cp -> return cp
data CPReadException = CPReadException FilePath CPError
deriving (Show, Typeable)
instance Exception CPReadException