-- | A newtype around a list of Strings representing blacklists. -- This is all to avoid an orphan instance of 'Configured' for -- [String] if we had defined one in e.g. 'OptionalConfiguration'. -- {-# LANGUAGE DeriveDataTypeable #-} module Lists ( Lists(..) ) where -- DC is needed only for the DCT.Configured instance of String. import qualified Data.Configurator as DC() import qualified Data.Configurator.Types as DCT ( Configured, Value( List ), convert ) import Data.Data ( Data ) import System.Console.CmdArgs.Default ( Default(..) ) import Data.Typeable ( Typeable ) -- | A (wrapper around a) list of blacklists. -- newtype Lists = Lists { get_lists :: [String] } deriving (Data, Show, Typeable) -- | The default list of white/blacklists. It's empty. -- instance Default Lists where def = Lists [] instance DCT.Configured Lists where -- | This allows us to read a 'Lists' object out of a Configurator -- config file. By default Configurator wouldn't know what to do, -- so we have to tell it that we expect a list, and if that list -- has strings in it, we can apply the Lists constructor to -- it. convert (DCT.List xs) = -- mapM gives us a Maybe [String] here. fmap Lists (mapM convert_string xs) where convert_string :: DCT.Value -> Maybe String convert_string = DCT.convert -- If we read anything other than a list of values out of the file, -- fail. convert _ = Nothing