log_level_help =
"How verbose should the logs be? One of INFO, WARNING, ERROR."
+-- | A description of the "remove" option.
+remove_help :: String
+remove_help =
+ "Remove files that have been successfully imported."
+
-- | A description of the "syslog" option.
syslog_help :: String
syslog_help =
connection_string = def &= typ "STRING" &= help connection_string_help,
log_file = def &= typFile &= help log_file_help,
log_level = def &= typ "LEVEL" &= help log_level_help,
+ remove = def &= typ "BOOL" &= help remove_help,
syslog = def &= typ "BOOL" &= help syslog_help,
xml_files = def &= typ "XMLFILES" &= args }
&= program program_name
connection_string :: ConnectionString,
log_file :: Maybe FilePath,
log_level :: Priority,
+ remove :: Bool,
syslog :: Bool }
deriving (Show)
connection_string = def,
log_file = def,
log_level = INFO,
+ remove = def,
syslog = def }
(merge (connection_string cfg) (OC.connection_string opt_cfg))
(OC.merge_maybes (log_file cfg) (OC.log_file opt_cfg))
(merge (log_level cfg) (OC.log_level opt_cfg))
+ (merge (remove cfg) (OC.remove opt_cfg))
(merge (syslog cfg) (OC.syslog opt_cfg))
where
-- | If the thing on the right is Just something, return that
let victims = [ p | (p, True) <- result_pairs ]
let imported_count = length victims
report_info $ "Imported " ++ (show imported_count) ++ " document(s) total."
- mapM_ (kill True) victims
+ when (remove cfg) $ mapM_ (kill True) victims
where
-- | Wrap these two actions into one function so that we don't
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)
--
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