]> gitweb.michael.orlitzky.com - mailbox-count.git/blobdiff - src/Configuration.hs
Make all connection string parameters optional.
[mailbox-count.git] / src / Configuration.hs
index 2fbc3979820497aa2bcd2539e6dd5f9e0f4e3ec7..e383abc263c0ee85878045c00f3293197cd6cb3a 100644 (file)
@@ -9,19 +9,22 @@ where
 
 import System.Console.CmdArgs.Default ( Default(..) )
 
-import qualified OptionalConfiguration as OC ( OptionalConfiguration(..) )
+import qualified OptionalConfiguration as OC (
+  OptionalConfiguration(..),
+  merge_maybes )
 
 -- | The main configuration data type. This will be passed to most of
 --   the important functions once it has been created.
+--
 data Configuration =
   Configuration {
     both   :: Bool,
-    database :: String,
+    database :: Maybe String,
     detail  :: Bool,
-    host :: String,
-    password :: String,
-    port :: Int,
-    username :: String }
+    host :: Maybe String,
+    password :: Maybe String,
+    port :: Maybe Int,
+    username :: Maybe String }
   deriving (Show)
 
 -- | A Configuration with all of its fields set to their default
@@ -29,12 +32,12 @@ data Configuration =
 instance Default Configuration where
   def = Configuration {
           both   = def,
-          database = "postfixadmin",
+          database = def,
           detail = def,
-          host = "localhost",
+          host = def,
           password = def,
-          port = 5432,
-          username = "postgres" }
+          port = def,
+          username = def }
 
 -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
 --   more or less the Monoid instance for 'OptionalConfiguration', but
@@ -45,12 +48,12 @@ merge_optional :: Configuration
 merge_optional cfg opt_cfg =
   Configuration
     (merge (both cfg) (OC.both opt_cfg))
-    (merge (database cfg) (OC.database opt_cfg))
+    (OC.merge_maybes (database cfg) (OC.database opt_cfg))
     (merge (detail cfg) (OC.detail opt_cfg))
-    (merge (host cfg) (OC.host opt_cfg))
-    (merge (password cfg) (OC.password opt_cfg))
-    (merge (port cfg) (OC.port opt_cfg))
-    (merge (username cfg) (OC.username opt_cfg))
+    (OC.merge_maybes (host cfg) (OC.host opt_cfg))
+    (OC.merge_maybes (password cfg) (OC.password opt_cfg))
+    (OC.merge_maybes (port cfg) (OC.port opt_cfg))
+    (OC.merge_maybes (username cfg) (OC.username opt_cfg))
   where
     -- | If the thing on the right is Just something, return that
     --   something, otherwise return the thing on the left.