]> gitweb.michael.orlitzky.com - dead/harbl.git/blobdiff - harbl-cli/src/Configuration.hs
Replace 'UserDomain' with 'Host' in the library.
[dead/harbl.git] / harbl-cli / src / Configuration.hs
diff --git a/harbl-cli/src/Configuration.hs b/harbl-cli/src/Configuration.hs
new file mode 100644 (file)
index 0000000..64adc7e
--- /dev/null
@@ -0,0 +1,48 @@
+-- | This module defines the 'Configuration' type, which is just a
+--   wrapper around all of the configuration options we accept on the
+--   command line.
+--
+module Configuration (
+  Configuration(..),
+  merge_optional )
+where
+
+import System.Console.CmdArgs.Default ( Default(..) )
+
+import qualified OptionalConfiguration as OC (
+  OptionalConfiguration(..) )
+import Hosts ( Hosts(..) )
+import Lists ( Lists(..) )
+
+
+-- | The main configuration data type. This will be passed to most of
+--   the important functions once it has been created.
+--
+data Configuration =
+  Configuration {
+    hosts  :: Hosts,
+    lists  :: Lists }
+    deriving (Show)
+
+
+-- | A Configuration with all of its fields set to their default
+--   values.
+--
+instance Default Configuration where
+  def = Configuration { hosts = def, lists = def }
+
+
+-- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
+--   more or less the Monoid instance for 'OptionalConfiguration', but
+--   since the two types are different, we have to repeat ourselves.
+--
+merge_optional :: Configuration
+               -> OC.OptionalConfiguration
+               -> Configuration
+merge_optional cfg opt_cfg =
+  Configuration all_hosts all_lists
+  where
+    all_hosts =
+      Hosts $ (get_hosts $ hosts cfg) ++ (get_hosts $ OC.hosts opt_cfg)
+    all_lists =
+      Lists $ (get_lists $ lists cfg) ++ (get_lists $ OC.lists opt_cfg)