aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-05-30 15:12:42 +1000
committerYuchen Pei <hi@ypei.me>2022-05-30 15:12:42 +1000
commit88ebd3366f661606138811c1af24364ef5c3a280 (patch)
treeee2c641fe34bfe2d7556be9c5681a7e5ee91a5e9
parentb454da8bf8f76e0c75a751a1a6cb93f480305199 (diff)
Added config file option
-rw-r--r--f2md.cabal4
-rw-r--r--src/Main.hs30
2 files changed, 26 insertions, 8 deletions
diff --git a/f2md.cabal b/f2md.cabal
index 28c43ae..5977e4b 100644
--- a/f2md.cabal
+++ b/f2md.cabal
@@ -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.")