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.
13 import qualified OptionalConfiguration as OC
16 Cfg { consumer_key :: String,
17 consumer_secret :: String,
18 access_token :: String,
19 access_secret :: String,
21 ignore_replies :: Bool,
22 ignore_retweets :: Bool,
23 sendmail_path :: String,
24 from_address :: Maybe String,
25 to_address :: Maybe String,
27 usernames :: [String] }
33 Cfg { consumer_key = "",
38 ignore_replies = False,
39 ignore_retweets = False,
40 sendmail_path = "/usr/sbin/sendmail",
41 from_address = Nothing,
46 merge_optional :: Cfg -> OC.OptionalCfg -> Cfg
47 merge_optional cfg opt_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))
62 merge :: a -> Maybe a -> a
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
73 -- If there are any optional usernames, use only those.
74 all_usernames = if (null (OC.usernames opt_cfg))
76 else (OC.usernames opt_cfg)