packages feed

cltw-1.1.4: src/main.hs

-- Copyright: 2010 Dino Morelli
-- License: BSD3 (see LICENSE)
-- Author: Dino Morelli <dino@ui3.info>

import Control.Monad.Reader
import System.Environment
import System.Exit

import Cltw.Common
import Cltw.Opts
import Cltw.Update
import Cltw.User


executeCommand :: String -> [String] -> Cltw ()

executeCommand cmd@"followers" _ = executeUsersCommand cmd

executeCommand cmd@"friends" _ = executeUsersCommand cmd

executeCommand "update" msg = postUpdate msg

-- This only gets invoked for the "help" command, hence the ExitSuccess
executeCommand _ _ = liftIO $ do
   putStrLn usageText
   exitWith ExitSuccess


errHandler :: String -> IO a
errHandler errMsg = do
   putStrLn errMsg
   exitWith $ ExitFailure 1


main :: IO ()
main = do
   (opts, cmd, rest) <- getArgs >>= parseOpts
   result <- runCltw opts $ executeCommand cmd rest
   either errHandler return result