]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/Configuration.hs
786586557226406b8828e644228f3cb03204d290
[dead/halcyon.git] / src / Configuration.hs
1 -- | This module defines the 'Cfg' type, which is just a wrapper
2 -- around all of the configuration options we accept on the command
3 -- line. We thread this throughout the rest of the program.
4 --
5
6 module Configuration (
7 Cfg(..),
8 default_config,
9 merge_optional )
10 where
11
12 import qualified OptionalConfiguration as OC ( OptionalCfg(..) )
13 import Usernames ( Usernames(..) )
14
15 data Cfg =
16 Cfg { consumer_key :: String,
17 consumer_secret :: String,
18 access_token :: String,
19 access_secret :: String,
20 heartbeat :: Int,
21 ignore_replies :: Bool,
22 ignore_retweets :: Bool,
23 sendmail_path :: String,
24 from_address :: Maybe String,
25 to_address :: Maybe String,
26 verbose :: Bool,
27 usernames :: Usernames }
28 deriving (Show)
29
30
31 default_config :: Cfg
32 default_config =
33 Cfg { consumer_key = "",
34 consumer_secret = "",
35 access_token = "",
36 access_secret = "",
37 heartbeat = 600,
38 ignore_replies = False,
39 ignore_retweets = False,
40 sendmail_path = "/usr/sbin/sendmail",
41 from_address = Nothing,
42 to_address = Nothing,
43 verbose = False,
44 usernames = Usernames [] }
45
46 merge_optional :: Cfg -> OC.OptionalCfg -> Cfg
47 merge_optional cfg opt_cfg =
48 Cfg
49 (merge (consumer_key cfg) (OC.consumer_key opt_cfg))
50 (merge (consumer_secret cfg) (OC.consumer_secret opt_cfg))
51 (merge (access_token cfg) (OC.access_token opt_cfg))
52 (merge (access_secret cfg) (OC.access_secret opt_cfg))
53 (merge (heartbeat cfg) (OC.heartbeat opt_cfg))
54 (merge (ignore_replies cfg) (OC.ignore_replies opt_cfg))
55 (merge (ignore_retweets cfg) (OC.ignore_retweets opt_cfg))
56 (merge (sendmail_path cfg) (OC.sendmail_path opt_cfg))
57 (merge' (from_address cfg) (OC.from_address opt_cfg))
58 (merge' (to_address cfg) (OC.to_address opt_cfg))
59 (merge (verbose cfg) (OC.verbose opt_cfg))
60 all_usernames
61 where
62 merge :: a -> Maybe a -> a
63 merge x Nothing = x
64 merge _ (Just y) = y
65
66 -- Used for the to/from address
67 merge' :: Maybe a -> Maybe a -> Maybe a
68 merge' Nothing Nothing = Nothing
69 merge' (Just x) Nothing = Just x
70 merge' Nothing (Just x) = Just x
71 merge' (Just _) (Just y) = Just y
72
73 -- If there are any optional usernames, use only those.
74 all_usernames = if (null (get_usernames (OC.usernames opt_cfg)))
75 then (usernames cfg)
76 else (OC.usernames opt_cfg)