]> gitweb.michael.orlitzky.com - dead/halcyon.git/blobdiff - src/Configuration.hs
Create a Usernames newtype to fix an orphan instance.
[dead/halcyon.git] / src / Configuration.hs
index b4b29f3687bb7e9429ab0959368841e208fc9ea1..095f5395f6bf7b6d0e4994ece60f453df1e5b614 100644 (file)
@@ -4,11 +4,14 @@
 --
 
 module Configuration (
-  Cfg(..)
+  Cfg(..),
+  default_config,
+  merge_optional
 )
 where
 
 import qualified OptionalConfiguration as OC
+import Usernames
 
 data Cfg =
   Cfg { consumer_key :: String,
@@ -21,8 +24,9 @@ data Cfg =
         sendmail_path :: String,
         from_address :: Maybe String,
         to_address :: Maybe String,
-        verbose :: Bool }
-
+        verbose :: Bool,
+        usernames :: Usernames }
+    deriving (Show)
 
 
 default_config :: Cfg
@@ -37,7 +41,8 @@ default_config =
         sendmail_path = "/usr/sbin/sendmail",
         from_address = Nothing,
         to_address = Nothing,
-        verbose = False }
+        verbose = False,
+        usernames = Usernames [] }
 
 merge_optional :: Cfg -> OC.OptionalCfg -> Cfg
 merge_optional cfg opt_cfg =
@@ -53,6 +58,7 @@ merge_optional cfg opt_cfg =
     (merge' (from_address cfg) (OC.from_address opt_cfg))
     (merge' (to_address cfg) (OC.to_address opt_cfg))
     (merge (verbose cfg) (OC.verbose opt_cfg))
+    all_usernames
   where
     merge :: a -> Maybe a -> a
     merge x Nothing  = x
@@ -64,3 +70,8 @@ merge_optional cfg opt_cfg =
     merge' (Just x) Nothing  = Just x
     merge' Nothing (Just x)  = Just x
     merge' (Just _) (Just y) = Just y
+
+    -- If there are any optional usernames, use only those.
+    all_usernames = if (null (get_usernames (OC.usernames opt_cfg)))
+                    then (usernames cfg)
+                    else (OC.usernames opt_cfg)