merge_maybes )
where
+-- System imports.
import qualified Data.Configurator as DC (
Worth(Optional),
load,
import System.Log ( Priority(..) )
import Text.Read ( readMaybe )
+-- Local imports.
import Backend ( Backend(..) )
import ConnectionString ( ConnectionString )
import Network.Services.TSN.Report ( report_error )
deriving instance Data Priority
deriving instance Typeable Priority
--- | The same as Configuration, except everything is optional. It's easy to
--- merge two of these by simply dropping the Nothings in favor of
--- the Justs. The 'feed_hosts' are left un-maybed so that cmdargs
--- can parse more than one of them.
+-- | The same as 'Configuration', except everything is optional. It's
+-- easy to merge two of these by simply dropping the 'Nothing's in
+-- favor of the 'Just's. The 'xml_files' are left un-maybed so that
+-- cmdargs can parse more than one of them.
--
data OptionalConfiguration =
OptionalConfiguration {
connection_string :: Maybe ConnectionString,
log_file :: Maybe FilePath,
log_level :: Maybe Priority,
+ remove :: Maybe Bool,
syslog :: Maybe Bool,
xml_files :: [FilePath] }
deriving (Show, Data, Typeable)
merge_maybes (Just _) (Just y) = Just y
--- | The Monoid instance for these lets us "combine" two
--- OptionalConfigurations. The "combine" operation that we'd like to
+-- | The Monoid instance for these lets us \"combine\" two
+-- OptionalConfigurations. The \"combine\" operation that we'd like to
-- perform is, essentially, to mash them together. So if we have two
-- OptionalConfigurations, each half full, we could combine them
-- into one big one.
--
instance Monoid OptionalConfiguration where
-- | An empty OptionalConfiguration.
- mempty = OptionalConfiguration Nothing Nothing Nothing Nothing Nothing []
+ mempty = OptionalConfiguration
+ Nothing
+ Nothing
+ Nothing
+ Nothing
+ Nothing
+ Nothing
+ []
-- | Combine @cfg1@ and @cfg2@, giving precedence to @cfg2@.
(merge_maybes (connection_string cfg1) (connection_string cfg2))
(merge_maybes (log_file cfg1) (log_file cfg2))
(merge_maybes (log_level cfg1) (log_level cfg2))
+ (merge_maybes (remove cfg1) (remove cfg2))
(merge_maybes (syslog cfg1) (syslog cfg2))
((xml_files cfg1) ++ (xml_files cfg2))
cfg_connection_string <- DC.lookup cfg "connection_string"
cfg_log_file <- DC.lookup cfg "log_file"
cfg_log_level <- DC.lookup cfg "log_level"
+ cfg_remove <- DC.lookup cfg "remove"
cfg_syslog <- DC.lookup cfg "syslog"
let cfg_xml_files = [] -- This won't be in the config file.
return $ OptionalConfiguration
cfg_connection_string
cfg_log_file
cfg_log_level
+ cfg_remove
cfg_syslog
cfg_xml_files