]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/Configuration.hs
Initial commit of something working.
[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. We thread this throughout the rest of the program.
4
5 module Configuration (
6 Configuration(..),
7 merge_optional )
8 where
9
10 import System.Console.CmdArgs.Default (Default(..))
11
12 import FeedHosts (FeedHosts(..))
13 import qualified OptionalConfiguration as OC (OptionalConfiguration(..))
14
15 data Configuration =
16 Configuration {
17 feed_hosts :: FeedHosts,
18 password :: String,
19 output_directory :: FilePath,
20 username :: String }
21 deriving (Show)
22
23 -- | A Configuration with all of its fields set to their default
24 -- values.
25 instance Default Configuration where
26 def = Configuration def def "." def
27
28 merge_optional :: Configuration
29 -> OC.OptionalConfiguration
30 -> Configuration
31 merge_optional cfg opt_cfg =
32 Configuration
33 all_feed_hosts
34 (merge (password cfg) (OC.password opt_cfg))
35 (merge (output_directory cfg) (OC.output_directory opt_cfg))
36 (merge (username cfg) (OC.username opt_cfg))
37 where
38 merge :: a -> Maybe a -> a
39 merge x Nothing = x
40 merge _ (Just y) = y
41
42 -- If there are any optional usernames, use only those.
43 all_feed_hosts = if (null (get_feed_hosts (OC.feed_hosts opt_cfg)))
44 then (feed_hosts cfg)
45 else (OC.feed_hosts opt_cfg)
46