]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/Configuration.hs
Tiny whitespace fix.
[dead/htsn.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 qualified OptionalConfiguration as OC (OptionalConfiguration(..))
14 import TSN.FeedHosts (FeedHosts(..))
15
16 data Configuration =
17 Configuration {
18 feed_hosts :: FeedHosts,
19 log_file :: FilePath,
20 log_level :: Priority,
21 password :: String,
22 output_directory :: FilePath,
23 syslog :: Bool,
24 username :: String }
25 deriving (Show)
26
27 -- | A Configuration with all of its fields set to their default
28 -- values.
29 instance Default Configuration where
30 def = Configuration def "htsn.log" INFO def "." True def
31
32
33 -- | Merge a Configuration with an OptionalConfiguration. This is more
34 -- or less the Monoid instance for OptionalConfiguration, but since
35 -- the two types are different, we have to repeat ourselves.
36 merge_optional :: Configuration
37 -> OC.OptionalConfiguration
38 -> Configuration
39 merge_optional cfg opt_cfg =
40 Configuration
41 all_feed_hosts
42 (merge (log_file cfg) (OC.log_file opt_cfg))
43 (merge (log_level cfg) (OC.log_level opt_cfg))
44 (merge (password cfg) (OC.password opt_cfg))
45 (merge (output_directory cfg) (OC.output_directory opt_cfg))
46 (merge (syslog cfg) (OC.syslog opt_cfg))
47 (merge (username cfg) (OC.username opt_cfg))
48 where
49 merge :: a -> Maybe a -> a
50 merge x Nothing = x
51 merge _ (Just y) = y
52
53 -- If there are any optional usernames, use only those.
54 all_feed_hosts = if (null (get_feed_hosts (OC.feed_hosts opt_cfg)))
55 then (feed_hosts cfg)
56 else (OC.feed_hosts opt_cfg)
57