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 TSN.FeedHosts (FeedHosts(..))
21 feed_hosts :: FeedHosts,
22 log_file :: Maybe FilePath,
23 log_level :: Priority,
24 output_directory :: FilePath,
27 run_as_group :: Maybe String,
28 run_as_user :: Maybe String,
33 -- | A Configuration with all of its fields set to their default
35 instance Default Configuration where
41 output_directory = ".",
43 pidfile = "/run/htsn.pid",
50 -- | Merge a Configuration with an OptionalConfiguration. This is more
51 -- or less the Monoid instance for OptionalConfiguration, but since
52 -- the two types are different, we have to repeat ourselves.
53 merge_optional :: Configuration
54 -> OC.OptionalConfiguration
56 merge_optional cfg opt_cfg =
58 (merge (daemonize cfg) (OC.daemonize opt_cfg))
60 (OC.merge_maybes (log_file cfg) (OC.log_file opt_cfg))
61 (merge (log_level cfg) (OC.log_level opt_cfg))
62 (merge (output_directory cfg) (OC.output_directory opt_cfg))
63 (merge (password cfg) (OC.password opt_cfg))
64 (merge (pidfile cfg) (OC.pidfile opt_cfg))
65 (OC.merge_maybes (run_as_group cfg) (OC.run_as_group opt_cfg))
66 (OC.merge_maybes (run_as_user cfg) (OC.run_as_user opt_cfg))
67 (merge (syslog cfg) (OC.syslog opt_cfg))
68 (merge (username cfg) (OC.username opt_cfg))
70 -- | If the thing on the right is Just something, return that
71 -- something, otherwise return the thing on the left.
72 merge :: a -> Maybe a -> a
76 -- If there are any optional usernames, use only those.
77 all_feed_hosts = if (null (get_feed_hosts (OC.feed_hosts opt_cfg)))
79 else (OC.feed_hosts opt_cfg)