1 -- | This module defines the 'Configuration' type, which is just a
2 -- wrapper around all of the configuration options we accept on the
10 import System.Console.CmdArgs.Default ( Default(..) )
11 import System.Log ( Priority( INFO ) )
13 import Backend ( Backend(..) )
14 import ConnectionString ( ConnectionString )
15 import qualified OptionalConfiguration as OC (
16 OptionalConfiguration(..),
19 -- | The main configuration data type. This will be passed to most of
20 -- the important functions once it has been created.
24 connection_string :: ConnectionString,
25 log_file :: Maybe FilePath,
26 log_level :: Priority,
30 -- | A Configuration with all of its fields set to their default
32 instance Default Configuration where
35 connection_string = def,
41 -- | Merge a Configuration with an OptionalConfiguration. This is more
42 -- or less the Monoid instance for OptionalConfiguration, but since
43 -- the two types are different, we have to repeat ourselves.
44 merge_optional :: Configuration
45 -> OC.OptionalConfiguration
47 merge_optional cfg opt_cfg =
49 (merge (backend cfg) (OC.backend opt_cfg))
50 (merge (connection_string cfg) (OC.connection_string opt_cfg))
51 (OC.merge_maybes (log_file cfg) (OC.log_file opt_cfg))
52 (merge (log_level cfg) (OC.log_level opt_cfg))
53 (merge (syslog cfg) (OC.syslog opt_cfg))
55 -- | If the thing on the right is Just something, return that
56 -- something, otherwise return the thing on the left.
57 merge :: a -> Maybe a -> a