X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FConfiguration.hs;h=a90af38435cbcd3df1fefd767f401203a4bfa169;hb=160caf38b6e936b6541b31b3c9bbe952ba0a4b15;hp=7b237c5f1d0d350de28b8d00bc711fabcc78ee2c;hpb=a2c2a1a6865be7b4cd17fb72de635bb9385728b9;p=dead%2Fhtsn.git diff --git a/src/Configuration.hs b/src/Configuration.hs index 7b237c5..a90af38 100644 --- a/src/Configuration.hs +++ b/src/Configuration.hs @@ -7,23 +7,29 @@ module Configuration ( merge_optional ) where -import System.Console.CmdArgs.Default (Default(..)) +import System.Console.CmdArgs.Default ( Default(..) ) +import System.Log ( Priority( INFO ) ) -import qualified OptionalConfiguration as OC (OptionalConfiguration(..)) +import qualified OptionalConfiguration as OC ( + OptionalConfiguration(..), + merge_maybes ) import TSN.FeedHosts (FeedHosts(..)) data Configuration = Configuration { feed_hosts :: FeedHosts, + log_file :: Maybe 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 def INFO def "." def def -- | Merge a Configuration with an OptionalConfiguration. This is more @@ -35,16 +41,21 @@ merge_optional :: Configuration merge_optional cfg opt_cfg = Configuration all_feed_hosts + (OC.merge_maybes (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 + -- | If the thing on the right is Just something, return that + -- something, otherwise return the thing on the left. merge :: a -> Maybe a -> a merge x Nothing = x merge _ (Just y) = y -- If there are any optional usernames, use only those. all_feed_hosts = if (null (get_feed_hosts (OC.feed_hosts opt_cfg))) - then (feed_hosts cfg) - else (OC.feed_hosts opt_cfg) + then (feed_hosts cfg) + else (OC.feed_hosts opt_cfg)