Add a "threshold" to the configuration.
[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 -- System imports.
11 import System.Console.CmdArgs.Default ( Default(..) )
12
13 -- Harbl library imports.
14 import Network.DNS.RBL.Weight ( Weight )
15
16 -- Local imports.
17 import qualified OptionalConfiguration as OC (
18 OptionalConfiguration(..),
19 merge_maybe,
20 merge_monoid )
21 import Hosts ( Hosts(..) )
22 import Lists ( Lists(..) )
23
24
25 -- | The main configuration data type. This will be passed to most of
26 -- the important functions once it has been created.
27 --
28 data Configuration =
29 Configuration {
30 hosts :: Hosts,
31 lists :: Lists,
32 threshold :: Weight }
33 deriving (Show)
34
35
36 -- | A Configuration with all of its fields set to their default
37 -- values.
38 --
39 instance Default Configuration where
40 def = Configuration { hosts = def,
41 lists = def,
42 threshold = def }
43
44
45 -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
46 -- more or less the Monoid instance for 'OptionalConfiguration', but
47 -- since the two types are different, we have to repeat ourselves.
48 --
49 merge_optional :: Configuration
50 -> OC.OptionalConfiguration
51 -> Configuration
52 merge_optional cfg opt_cfg = Configuration hs ls t
53 where
54 hs = OC.merge_monoid (hosts cfg) (OC.hosts opt_cfg)
55 ls = OC.merge_monoid (lists cfg) (OC.lists opt_cfg)
56 t = OC.merge_maybe (threshold cfg) (OC.threshold opt_cfg)