64adc7e6a7bb330b396cf0603b3381f61e49edca
[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 System.Console.CmdArgs.Default ( Default(..) )
11
12 import qualified OptionalConfiguration as OC (
13 OptionalConfiguration(..) )
14 import Hosts ( Hosts(..) )
15 import Lists ( Lists(..) )
16
17
18 -- | The main configuration data type. This will be passed to most of
19 -- the important functions once it has been created.
20 --
21 data Configuration =
22 Configuration {
23 hosts :: Hosts,
24 lists :: Lists }
25 deriving (Show)
26
27
28 -- | A Configuration with all of its fields set to their default
29 -- values.
30 --
31 instance Default Configuration where
32 def = Configuration { hosts = def, lists = def }
33
34
35 -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
36 -- more or less the Monoid instance for 'OptionalConfiguration', but
37 -- since the two types are different, we have to repeat ourselves.
38 --
39 merge_optional :: Configuration
40 -> OC.OptionalConfiguration
41 -> Configuration
42 merge_optional cfg opt_cfg =
43 Configuration all_hosts all_lists
44 where
45 all_hosts =
46 Hosts $ (get_hosts $ hosts cfg) ++ (get_hosts $ OC.hosts opt_cfg)
47 all_lists =
48 Lists $ (get_lists $ lists cfg) ++ (get_lists $ OC.lists opt_cfg)