]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/Configuration.hs
Add an OptionalConfiguration type and parse one from ~/.twatrc.
[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 )
9 where
10
11 import qualified OptionalConfiguration as OC
12
13 data Cfg =
14 Cfg { consumer_key :: String,
15 consumer_secret :: String,
16 access_token :: String,
17 access_secret :: String,
18 heartbeat :: Int,
19 ignore_replies :: Bool,
20 ignore_retweets :: Bool,
21 sendmail_path :: String,
22 from_address :: Maybe String,
23 to_address :: Maybe String,
24 verbose :: Bool }
25
26
27
28 default_config :: Cfg
29 default_config =
30 Cfg { consumer_key = "",
31 consumer_secret = "",
32 access_token = "",
33 access_secret = "",
34 heartbeat = 600,
35 ignore_replies = False,
36 ignore_retweets = False,
37 sendmail_path = "/usr/sbin/sendmail",
38 from_address = Nothing,
39 to_address = Nothing,
40 verbose = False }
41
42 merge_optional :: Cfg -> OC.OptionalCfg -> Cfg
43 merge_optional cfg opt_cfg =
44 Cfg
45 (merge (consumer_key cfg) (OC.consumer_key opt_cfg))
46 (merge (consumer_secret cfg) (OC.consumer_secret opt_cfg))
47 (merge (access_token cfg) (OC.access_token opt_cfg))
48 (merge (access_secret cfg) (OC.access_secret opt_cfg))
49 (merge (heartbeat cfg) (OC.heartbeat opt_cfg))
50 (merge (ignore_replies cfg) (OC.ignore_replies opt_cfg))
51 (merge (ignore_retweets cfg) (OC.ignore_retweets opt_cfg))
52 (merge (sendmail_path cfg) (OC.sendmail_path opt_cfg))
53 (merge' (from_address cfg) (OC.from_address opt_cfg))
54 (merge' (to_address cfg) (OC.to_address opt_cfg))
55 (merge (verbose cfg) (OC.verbose opt_cfg))
56 where
57 merge :: a -> Maybe a -> a
58 merge x Nothing = x
59 merge _ (Just y) = y
60
61 -- Used for the to/from address
62 merge' :: Maybe a -> Maybe a -> Maybe a
63 merge' Nothing Nothing = Nothing
64 merge' (Just x) Nothing = Just x
65 merge' Nothing (Just x) = Just x
66 merge' (Just _) (Just y) = Just y