]> gitweb.michael.orlitzky.com - dead/halcyon.git/blobdiff - src/Configuration.hs
Clean up a bunch of code and comments.
[dead/halcyon.git] / src / Configuration.hs
index 786586557226406b8828e644228f3cb03204d290..c2136431577a574cd2ace86a67e93dc7d3747e2d 100644 (file)
@@ -5,13 +5,18 @@
 
 module Configuration (
   Cfg(..),
-  default_config,
   merge_optional )
 where
 
+import System.Console.CmdArgs.Default ( Default(..) )
+
 import qualified OptionalConfiguration as OC ( OptionalCfg(..) )
 import Usernames ( Usernames(..) )
 
+
+-- | The main configuration data type. It contains all options that
+--   can be set in a config file or on the command line.
+--
 data Cfg =
   Cfg { consumer_key :: String,
         consumer_secret :: String,
@@ -20,7 +25,7 @@ data Cfg =
         heartbeat :: Int,
         ignore_replies :: Bool,
         ignore_retweets :: Bool,
-        sendmail_path :: String,
+        sendmail_path :: FilePath,
         from_address :: Maybe String,
         to_address :: Maybe String,
         verbose :: Bool,
@@ -28,21 +33,27 @@ data Cfg =
     deriving (Show)
 
 
-default_config :: Cfg
-default_config =
-  Cfg { consumer_key = "",
-        consumer_secret = "",
-        access_token = "",
-        access_secret = "",
-        heartbeat = 600,
-        ignore_replies = False,
-        ignore_retweets = False,
-        sendmail_path = "/usr/sbin/sendmail",
-        from_address = Nothing,
-        to_address = Nothing,
-        verbose = False,
-        usernames = Usernames [] }
+instance Default Cfg where
+  -- | A 'Cfg' with all of its fields set to their default values.
+  --
+  def = Cfg { consumer_key = def,
+              consumer_secret = def,
+              access_token = def,
+              access_secret = def,
+              heartbeat = 600,
+              ignore_replies = def,
+              ignore_retweets = def,
+              sendmail_path = "/usr/sbin/sendmail",
+              from_address = def,
+              to_address = def,
+              verbose = def,
+              usernames = def }
 
+
+-- | Merge a 'Cfg' with an 'OptionalCfg'. This is more or less the
+--   Monoid instance for 'OptionalCfg', but since the two types are
+--   different, we have to repeat ourselves.
+--
 merge_optional :: Cfg -> OC.OptionalCfg -> Cfg
 merge_optional cfg opt_cfg =
   Cfg