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 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
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
-- 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)