aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/Main.hs b/src/Main.hs
index ec602cc..42566d7 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text as T
+import Options.Applicative
import Control.Monad.IO.Class
import Control.Monad.Logger
import System.Directory
@@ -11,6 +12,19 @@ import F2Md.Export
import F2Md.Config
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
+ 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 root dbPath feed = do
@@ -20,10 +34,12 @@ processFeed root dbPath feed = do
liftIO $ mapM_ (writeMessage root) msgs
whenJust dbPath $ \dbPath' -> liftIO $ updateLastUpdated' dbPath' feed msgs
-main :: IO ()
-main = do
- (feeds, maildir, dbPath) <- getUserdata "./.f2m.json"
- whenJust maildir $ \root -> do
- mapM_ (createDirectoryIfMissing True)
- [root </> "new", root </> "cur", root </> "tmp"]
- mapM_ (runStdoutLoggingT . processFeed root dbPath) feeds
+data Options = Options
+ { configPath :: 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.")