X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fharbl.git;a=blobdiff_plain;f=harbl-cli%2Fsrc%2FConfiguration.hs;fp=harbl-cli%2Fsrc%2FConfiguration.hs;h=64adc7e6a7bb330b396cf0603b3381f61e49edca;hp=0000000000000000000000000000000000000000;hb=b55e5db2a68be5d69b970bbe4b5ad447881abd3d;hpb=c4d41b93ec02ff4dc762163441ebefb0324e6f07 diff --git a/harbl-cli/src/Configuration.hs b/harbl-cli/src/Configuration.hs new file mode 100644 index 0000000..64adc7e --- /dev/null +++ b/harbl-cli/src/Configuration.hs @@ -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)