]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/Configuration.hs
Don't remove imported files by default.
[dead/htsn-import.git] / 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 import System.Log ( Priority( INFO ) )
12
13 import Backend ( Backend(..) )
14 import ConnectionString ( ConnectionString )
15 import qualified OptionalConfiguration as OC (
16 OptionalConfiguration(..),
17 merge_maybes )
18
19 -- | The main configuration data type. This will be passed to most of
20 -- the important functions once it has been created.
21 data Configuration =
22 Configuration {
23 backend :: Backend,
24 connection_string :: ConnectionString,
25 log_file :: Maybe FilePath,
26 log_level :: Priority,
27 remove :: Bool,
28 syslog :: Bool }
29 deriving (Show)
30
31 -- | A Configuration with all of its fields set to their default
32 -- values.
33 instance Default Configuration where
34 def = Configuration {
35 backend = def,
36 connection_string = def,
37 log_file = def,
38 log_level = INFO,
39 remove = def,
40 syslog = def }
41
42
43 -- | Merge a Configuration with an OptionalConfiguration. This is more
44 -- or less the Monoid instance for OptionalConfiguration, but since
45 -- the two types are different, we have to repeat ourselves.
46 merge_optional :: Configuration
47 -> OC.OptionalConfiguration
48 -> Configuration
49 merge_optional cfg opt_cfg =
50 Configuration
51 (merge (backend cfg) (OC.backend opt_cfg))
52 (merge (connection_string cfg) (OC.connection_string opt_cfg))
53 (OC.merge_maybes (log_file cfg) (OC.log_file opt_cfg))
54 (merge (log_level cfg) (OC.log_level opt_cfg))
55 (merge (remove cfg) (OC.remove opt_cfg))
56 (merge (syslog cfg) (OC.syslog opt_cfg))
57 where
58 -- | If the thing on the right is Just something, return that
59 -- something, otherwise return the thing on the left.
60 merge :: a -> Maybe a -> a
61 merge x Nothing = x
62 merge _ (Just y) = y
63