a6798e97f08f38803edb0116a2f5080bffae5465
[dead/harbl.git] / harbl-cli / src / Configuration.hs
1 -- | This module defines the 'Configuration' type, which is just a
2 -- wrapper around all of the configuration options we accept on the
3 -- command line.
4 --
5 module Configuration (
6 Configuration(..),
7 merge_optional )
8 where
9
10 import Data.Monoid ( Monoid(..) )
11 import System.Console.CmdArgs.Default ( Default(..) )
12
13 -- From the harbl library.
14 import Network.DNS.RBL.Weight ( Weight )
15
16 import qualified OptionalConfiguration as OC (
17 OptionalConfiguration(..) )
18 import Hosts ( Hosts(..) )
19 import Lists ( Lists(..) )
20
21
22 -- | The main configuration data type. This will be passed to most of
23 -- the important functions once it has been created.
24 --
25 data Configuration =
26 Configuration {
27 hosts :: Hosts,
28 lists :: Lists }
29 -- threshold :: Weight }
30 deriving (Show)
31
32
33 -- | A Configuration with all of its fields set to their default
34 -- values.
35 --
36 instance Default Configuration where
37 def = Configuration { hosts = def,
38 lists = def }
39 -- threshold = def }
40
41
42 -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
43 -- more or less the Monoid instance for 'OptionalConfiguration', but
44 -- since the two types are different, we have to repeat ourselves.
45 --
46 merge_optional :: Configuration
47 -> OC.OptionalConfiguration
48 -> Configuration
49 merge_optional cfg opt_cfg =
50 Configuration all_hosts all_lists
51 where
52 all_hosts = (hosts cfg) `mappend` (OC.hosts opt_cfg)
53 all_lists = (lists cfg) `mappend` (OC.lists opt_cfg)