Commits

Anonymous committed ceb9943

Clean-up.

Comments (0)

Files changed (2)

 import qualified Imm.Options as Options
 import Imm.Util
 
-import Control.Concurrent.Async
 import Control.Lens hiding (Action, (??))
 import Control.Monad.Error hiding(when)
 import Control.Monad.Reader hiding(when)
 
 -- | Main function to call in the configuration file.
 imm :: [ConfigFeed] -> IO ()
-imm feedsFromConfig = Options.run $ readOptions Options.action >>= dispatch1 feedsFromConfig
+imm feedsFromConfig = Options.run $ readOptions Options.action >>= dispatch feedsFromConfig
 
 
-dispatch1 :: [ConfigFeed] -> Options.Action -> ReaderT Options.CliOptions IO ()
-dispatch1 _ Help        = io $ putStrLn Options.usage >> exitSuccess
-dispatch1 _ ShowVersion = io $ putStrLn (showVersion version) >> exitSuccess
-dispatch1 _ Recompile   = io $ Dyre.recompile >>= maybe exitSuccess (\e -> putStrLn e >> exitFailure)
-dispatch1 _ Import      = io getContents >>= Core.importOPML >> io exitSuccess
-dispatch1 feedsFromConfig (Run action) = do
+dispatch :: [ConfigFeed] -> Options.Action -> ReaderT Options.CliOptions IO ()
+dispatch _ Help        = io $ putStrLn Options.usage >> exitSuccess
+dispatch _ ShowVersion = io $ putStrLn (showVersion version) >> exitSuccess
+dispatch _ Recompile   = io $ Dyre.recompile >>= maybe exitSuccess (\e -> putStrLn e >> exitFailure)
+dispatch _ Import      = io getContents >>= Core.importOPML >> io exitSuccess
+dispatch feedsFromConfig (Run action) = do
     dyreMode         <- readOptions Options.dyreMode
     feedsFromOptions <- readOptions Options.feedsList
     dataDir          <- readOptions Options.dataDirectory
 
     io $ Dyre.wrap dyreMode realMain (action, dataDir, feedsFromOptions, feedsFromConfig)
 
-
-dispatch2 :: (Config -> Config) -> Feed.Action -> Core.FeedList -> IO ()
-dispatch2 baseConfig Feed.Check        feeds = void $ mapConcurrently (Core.check baseConfig) feeds
-dispatch2 baseConfig Feed.ShowStatus   feeds = mapM_ (Core.showStatus baseConfig) feeds
-dispatch2 baseConfig Feed.MarkAsRead   feeds = mapM_ (Core.markAsRead baseConfig) feeds
-dispatch2 baseConfig Feed.MarkAsUnread feeds = mapM_ (Core.markAsUnread baseConfig) feeds
-dispatch2 baseConfig Feed.Update       feeds = void $ mapConcurrently (Core.update baseConfig) feeds
-
-
 validateFeeds :: [ConfigFeed] -> [URI] -> ([String], Core.FeedList)
 validateFeeds feedsFromConfig feedsFromOptions = (errors ++ errors', null feedsFromOptions ? feedsOK ?? feedsOK')
   where
     when   (null feedsOK) $ warningM "imm.boot"   "Nothing to process. Exiting..." >> exitFailure
     -- io . debugM "imm.boot" . unlines $ "Feeds to be processed:":(map (show . snd) feedsOK)
 
-    dispatch2 baseConfig action feedsOK
+    Core.dispatch baseConfig action feedsOK
   where
     (errors, feedsOK) = validateFeeds feedsFromConfig feedsFromOptions
     baseConfig        = maybe id (set (fileDatabase . directory)) dataDir
     FeedConfig,
     FeedList,
 -- * Actions
+    dispatch,
     importOPML,
     check,
     showStatus,
 import Imm.OPML as OPML
 import Imm.Util
 
+import Control.Concurrent.Async
 import Control.Monad hiding(forM_, mapM_)
 import Control.Monad.Error hiding(forM_, mapM_)
 -- import Control.Monad.Reader hiding(forM_, mapM_)
 -- }}}
 
 
+dispatch :: (Config -> Config) -> Feed.Action -> FeedList -> IO ()
+dispatch baseConfig Feed.Check        feeds = void $ mapConcurrently (check baseConfig) feeds
+dispatch baseConfig Feed.ShowStatus   feeds = mapM_ (showStatus baseConfig) feeds
+dispatch baseConfig Feed.MarkAsRead   feeds = mapM_ (markAsRead baseConfig) feeds
+dispatch baseConfig Feed.MarkAsUnread feeds = mapM_ (markAsUnread baseConfig) feeds
+dispatch baseConfig Feed.Update       feeds = void $ mapConcurrently (update baseConfig) feeds
+
+
 importOPML :: (MonadBase IO m, MonadPlus m) => String -> m ()
 importOPML = mapM_ addFeeds . OPML.read