diff options
-rw-r--r-- | f2md.cabal | 4 | ||||
-rw-r--r-- | src/Main.hs | 30 |
2 files changed, 26 insertions, 8 deletions
@@ -32,6 +32,8 @@ executable f2md -- LANGUAGE extensions used by modules in this package. -- other-extensions: build-depends: - base, uuid, syb, feed, time, text, unix, hostname, random, filepath, directory, extra, xml-types, process, aeson, bytestring, unordered-containers, monad-logger, cryptonite + base, uuid, syb, feed, time, text, unix, hostname, random, filepath, + directory, extra, xml-types, process, aeson, bytestring, + unordered-containers, monad-logger, cryptonite, optparse-applicative hs-source-dirs: src default-language: Haskell2010 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.") |