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(..),
16 import FeedHosts (FeedHosts(..))
18 -- | The main configuration data type. This will be passed to most of
19 -- the important functions once it has been created.
23 feed_hosts :: FeedHosts,
24 log_file :: Maybe FilePath,
25 log_level :: Priority,
26 output_directory :: FilePath,
29 run_as_group :: Maybe String,
30 run_as_user :: Maybe String,
35 -- | A Configuration with all of its fields set to their default
37 instance Default Configuration where
43 output_directory = ".",
45 pidfile = "/run/htsn/htsn.pid",
52 -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
53 -- more or less the Monoid instance for 'OptionalConfiguration', but
54 -- since the two types are different, we have to repeat ourselves.
55 merge_optional :: Configuration
56 -> OC.OptionalConfiguration
58 merge_optional cfg opt_cfg =
60 (merge (daemonize cfg) (OC.daemonize opt_cfg))
62 (OC.merge_maybes (log_file cfg) (OC.log_file opt_cfg))
63 (merge (log_level cfg) (OC.log_level opt_cfg))
64 (merge (output_directory cfg) (OC.output_directory opt_cfg))
65 (merge (password cfg) (OC.password opt_cfg))
66 (merge (pidfile cfg) (OC.pidfile opt_cfg))
67 (OC.merge_maybes (run_as_group cfg) (OC.run_as_group opt_cfg))
68 (OC.merge_maybes (run_as_user cfg) (OC.run_as_user opt_cfg))
69 (merge (syslog cfg) (OC.syslog opt_cfg))
70 (merge (username cfg) (OC.username opt_cfg))
72 -- | If the thing on the right is Just something, return that
73 -- something, otherwise return the thing on the left.
74 merge :: a -> Maybe a -> a
78 -- If there are any optional usernames, use only those.
79 all_feed_hosts = if (null (get_feed_hosts (OC.feed_hosts opt_cfg)))
81 else (OC.feed_hosts opt_cfg)