-- | 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. module Configuration ( Configuration(..), merge_optional ) where import System.Console.CmdArgs.Default (Default(..)) import FeedHosts (FeedHosts(..)) import qualified OptionalConfiguration as OC (OptionalConfiguration(..)) data Configuration = Configuration { feed_hosts :: FeedHosts, password :: String, output_directory :: FilePath, 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 merge_optional :: Configuration -> OC.OptionalConfiguration -> Configuration merge_optional cfg opt_cfg = Configuration all_feed_hosts (merge (password cfg) (OC.password opt_cfg)) (merge (output_directory cfg) (OC.output_directory opt_cfg)) (merge (username cfg) (OC.username opt_cfg)) where 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)