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.
11 import System.Console.CmdArgs.Default ( Default(..) )
13 import qualified OptionalConfiguration as OC ( OptionalCfg(..) )
14 import Usernames ( Usernames(..) )
17 -- | The main configuration data type. It contains all options that
18 -- can be set in a config file or on the command line.
21 Cfg { consumer_key :: String,
22 consumer_secret :: String,
23 access_token :: String,
24 access_secret :: String,
26 ignore_replies :: Bool,
27 ignore_retweets :: Bool,
28 sendmail_path :: FilePath,
29 from_address :: Maybe String,
30 to_address :: Maybe String,
32 usernames :: Usernames }
36 instance Default Cfg where
37 -- | A 'Cfg' with all of its fields set to their default values.
39 def = Cfg { consumer_key = def,
40 consumer_secret = def,
45 ignore_retweets = def,
46 sendmail_path = "/usr/sbin/sendmail",
53 -- | Merge a 'Cfg' with an 'OptionalCfg'. This is more or less the
54 -- Monoid instance for 'OptionalCfg', but since the two types are
55 -- different, we have to repeat ourselves.
57 merge_optional :: Cfg -> OC.OptionalCfg -> Cfg
58 merge_optional cfg opt_cfg =
60 (merge (consumer_key cfg) (OC.consumer_key opt_cfg))
61 (merge (consumer_secret cfg) (OC.consumer_secret opt_cfg))
62 (merge (access_token cfg) (OC.access_token opt_cfg))
63 (merge (access_secret cfg) (OC.access_secret opt_cfg))
64 (merge (heartbeat cfg) (OC.heartbeat opt_cfg))
65 (merge (ignore_replies cfg) (OC.ignore_replies opt_cfg))
66 (merge (ignore_retweets cfg) (OC.ignore_retweets opt_cfg))
67 (merge (sendmail_path cfg) (OC.sendmail_path opt_cfg))
68 (merge' (from_address cfg) (OC.from_address opt_cfg))
69 (merge' (to_address cfg) (OC.to_address opt_cfg))
70 (merge (verbose cfg) (OC.verbose opt_cfg))
73 merge :: a -> Maybe a -> a
77 -- Used for the to/from address
78 merge' :: Maybe a -> Maybe a -> Maybe a
79 merge' Nothing Nothing = Nothing
80 merge' (Just x) Nothing = Just x
81 merge' Nothing (Just x) = Just x
82 merge' (Just _) (Just y) = Just y
84 -- If there are any optional usernames, use only those.
85 all_usernames = if (null (get_usernames (OC.usernames opt_cfg)))
87 else (OC.usernames opt_cfg)