diff options
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/src/Main.hs b/src/Main.hs index e5b33d4..060a823 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -34,24 +34,33 @@ import F2Md.Config import Data.Maybe import System.FilePath +-- TODO: kill on double C-c main :: IO () main = do options <- execParser opts - (feeds, mbMaildir, mbDbPath) <- getUserdata $ oConfigPath options - let root = fromMaybe (oMaildir options) mbMaildir - mapM_ (createDirectoryIfMissing True) - [root </> "new", root </> "cur", root </> "tmp"] - let dbPath = fromMaybe (oDbPath options) mbDbPath - mapM_ (\feed -> - catch (runStdoutLoggingT $ processFeed root dbPath feed) - (\e -> runStderrLoggingT $ logErrorN $ - (T.pack $ show (e :: SomeException)) <> "\n")) - feeds + extConfs <- getUserdata $ oConfigPath options + mapM_ processConfig extConfs where opts = info (progParser <**> helper) (fullDesc <> progDesc "f2md feeds to maildir" <> header "f2md - a utility to pull new items \ \from feeds and write them to maildir") +processConfig :: ExtConf -> IO () +processConfig (ExtConf dbPath maildir feeds) = do + mapM_ (createDirectoryIfMissing True) + [maildir </> "new", maildir </> "cur", maildir </> "tmp"] + runStdoutLoggingT $ + logInfoN $ "Updating " <> T.pack (show $ length feeds) <> + " feeds for " <> T.pack maildir <> "..." + mapM_ (\feed -> + catch (runStdoutLoggingT $ processFeed maildir dbPath feed) + (\e -> runStdoutLoggingT $ logErrorN $ T.pack (show (e :: SomeException)))) + feeds + +data Options = Options + { oConfigPath :: FilePath + } + -- TODO: update db on interruption with the latest date processFeed :: FilePath -> FilePath -> FeedUserdata -> LoggingT IO () processFeed root dbPath feed = do @@ -61,22 +70,9 @@ processFeed root dbPath feed = do liftIO $ mapM_ (writeMessage root) msgs liftIO $ updateLastUpdated dbPath feed msgs -data Options = Options - { oConfigPath :: FilePath - , oDbPath :: FilePath - , oMaildir :: FilePath - } - progParser :: Parser Options progParser = Options <$> strOption (long "config" <> short 'c' <> metavar "CONFIG" <> value "~/.f2md.json" <> showDefault <> help "Config file storing feeds, maildir \ \location and timestamp file location.") - <*> strOption (long "db" <> short 'd' <> metavar "DB" - <> value "~/.f2mdb.json" <> showDefault - <> help "Path to db file storing timestamps of feeds.") - <*> strOption (long "maildir" <> short 'm' <> metavar "MAILDIR" - <> value "~/mail/f2md" <> showDefault - <> help "Path to maildir root to deposit the maildir \ - \message files.") |