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 qualified OptionalConfiguration as OC (
14 OptionalConfiguration(..),
18 -- | The main configuration data type. This will be passed to most of
19 -- the important functions once it has been created.
22 connection_string :: String,
23 log_file :: Maybe FilePath,
24 log_level :: Priority,
28 -- | A Configuration with all of its fields set to their default
30 instance Default Configuration where
32 connection_string = def,
38 -- | Merge a Configuration with an OptionalConfiguration. This is more
39 -- or less the Monoid instance for OptionalConfiguration, but since
40 -- the two types are different, we have to repeat ourselves.
41 merge_optional :: Configuration
42 -> OC.OptionalConfiguration
44 merge_optional cfg opt_cfg =
46 (merge (connection_string cfg) (OC.connection_string opt_cfg))
47 (OC.merge_maybes (log_file cfg) (OC.log_file opt_cfg))
48 (merge (log_level cfg) (OC.log_level opt_cfg))
49 (merge (syslog cfg) (OC.syslog opt_cfg))
51 -- | If the thing on the right is Just something, return that
52 -- something, otherwise return the thing on the left.
53 merge :: a -> Maybe a -> a