]> gitweb.michael.orlitzky.com - list-remote-forwards.git/blob - src/MxList.hs
list-remote-forwards.cabal: delete the redundant description
[list-remote-forwards.git] / src / MxList.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2
3 -- | A newtype around a list of Strings which represent the MXes whose
4 -- remote forwards we don't report. This is all to avoid an orphan
5 -- instance of Configured for [String] if we had defined one in
6 -- e.g. 'OptionalConfiguration'.
7 --
8 module MxList (
9 MxList( MxList, get_mxs ) )
10 where
11
12 -- DC is needed only for the DCT.Configured instance of String.
13 import qualified Data.Configurator as DC()
14 import qualified Data.Configurator.Types as DCT (
15 Configured,
16 Value( List ),
17 convert )
18 import Data.Data (Data)
19 import System.Console.CmdArgs.Default ( Default( def ) )
20
21
22 -- | A (wrapper around a) list of MX hostnames.
23 --
24 newtype MxList =
25 MxList { get_mxs :: [String] }
26 deriving (Data, Show)
27
28
29 -- | The default (empty) list of MXes.
30 --
31 instance Default MxList where
32 def = MxList []
33
34
35 instance DCT.Configured MxList where
36 -- | This allows us to read a MxList object out of a Configurator
37 -- config file. By default Configurator wouldn't know what to do,
38 -- so we have to tell it that we expect a list, and if that list
39 -- has strings in it, we can apply the MxList constructor to
40 -- it.
41 convert (DCT.List xs) =
42 -- mapM gives us a Maybe [String] here.
43 fmap MxList (mapM convert_string xs)
44 where
45 convert_string :: DCT.Value -> Maybe String
46 convert_string = DCT.convert
47
48 -- If we read anything other than a list of values out of the file,
49 -- fail.
50 convert _ = Nothing