X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FConfiguration.hs;h=6234821c698f9de444101c5dd210a6a28db15223;hb=7c3e8169dfce7de580f2f224d0845de01b379249;hp=a382a9d77244504386a6e2025b8b078db98b7b5b;hpb=d4d924b26e451aec9ad84b6d9d376ba2aeab3422;p=dead%2Fhtsn.git diff --git a/src/Configuration.hs b/src/Configuration.hs index a382a9d..6234821 100644 --- a/src/Configuration.hs +++ b/src/Configuration.hs @@ -1,38 +1,49 @@ -- | This module defines the 'Configuration' type, which is just a -- wrapper around all of the configuration options we accept on the --- command line. We thread this throughout the rest of the program. - +-- command line. +-- module Configuration ( Configuration(..), merge_optional ) where -import System.Console.CmdArgs.Default (Default(..)) +import System.Console.CmdArgs.Default ( Default(..) ) +import System.Log ( Priority( INFO ) ) -import FeedHosts (FeedHosts(..)) import qualified OptionalConfiguration as OC (OptionalConfiguration(..)) +import TSN.FeedHosts (FeedHosts(..)) data Configuration = Configuration { feed_hosts :: FeedHosts, + log_file :: FilePath, + log_level :: Priority, password :: String, output_directory :: FilePath, + syslog :: Bool, username :: String } deriving (Show) -- | A Configuration with all of its fields set to their default -- values. instance Default Configuration where - def = Configuration def def "." def + def = Configuration def "htsn.log" INFO def "." True 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_feed_hosts + (merge (log_file cfg) (OC.log_file opt_cfg)) + (merge (log_level cfg) (OC.log_level opt_cfg)) (merge (password cfg) (OC.password opt_cfg)) (merge (output_directory cfg) (OC.output_directory opt_cfg)) + (merge (syslog cfg) (OC.syslog opt_cfg)) (merge (username cfg) (OC.username opt_cfg)) where merge :: a -> Maybe a -> a