aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/Main.hs b/src/Main.hs
index cf0f1af..ca71b29 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -30,36 +30,48 @@ import F2Md.Types
import F2Md.Import
import F2Md.Export
import F2Md.Config
+import Data.Maybe
import System.FilePath
main :: IO ()
main = do
options <- execParser opts
- (feeds, maildir, dbPath) <- getUserdata $ configPath options
- whenJust maildir $ \root -> do
- mapM_ (createDirectoryIfMissing True)
- [root </> "new", root </> "cur", root </> "tmp"]
- mapM_ (runStdoutLoggingT . processFeed root dbPath) feeds
+ (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_ (runStdoutLoggingT . processFeed root dbPath) feeds
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")
-- TODO: update db on interruption with the latest date
-processFeed :: FilePath -> Maybe FilePath -> FeedUserdata -> LoggingT IO ()
+processFeed :: FilePath -> FilePath -> FeedUserdata -> LoggingT IO ()
processFeed root dbPath feed = do
logInfoN $ "Fetching " <> fuUrl feed <> "..."
msgs <- liftIO $ toMessagesFromUrl (fuUrl feed) (fuLastUpdated feed)
logInfoN $ "Writing " <> T.pack (show $ length msgs) <> " messages..."
liftIO $ mapM_ (writeMessage root) msgs
- whenJust dbPath $ \dbPath' -> liftIO $ updateLastUpdated' dbPath' feed msgs
+ liftIO $ updateLastUpdated dbPath feed msgs
data Options = Options
- { configPath :: FilePath }
+ { 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.")
+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.")