git-annex/git-annex.hs

38 lines
887 B
Haskell
Raw Normal View History

2010-10-10 04:18:16 +00:00
{- git-annex main program
- -}
import System.IO
2010-10-10 22:05:37 +00:00
import System.Environment
import Control.Exception
2010-10-10 22:05:37 +00:00
import CmdLine
2010-10-10 19:04:18 +00:00
import Annex
2010-10-10 04:18:16 +00:00
main = do
2010-10-10 22:05:37 +00:00
args <- getArgs
(mode, files) <- argvToMode args
2010-10-10 22:05:37 +00:00
2010-10-10 22:25:31 +00:00
state <- startAnnex
2010-10-10 16:41:20 +00:00
2010-10-11 22:39:09 +00:00
tryRun 0 0 $ map (\f -> dispatch state mode f) files
{- Tries to run a series of actions, not stopping if some error out,
- and propigating an overall error status at the end. -}
2010-10-11 22:39:09 +00:00
tryRun errnum oknum [] = do
if (errnum > 0)
2010-10-11 22:39:36 +00:00
then error $ (show errnum) ++ " failed ; " ++ show (oknum) ++ " ok"
else return ()
2010-10-11 22:39:09 +00:00
tryRun errnum oknum (a:as) = do
result <- try (a)::IO (Either SomeException ())
case (result) of
Left err -> do
showErr err
2010-10-11 22:39:09 +00:00
tryRun (errnum + 1) oknum as
Right _ -> tryRun errnum (oknum + 1) as
{- Exception pretty-printing. -}
showErr :: SomeException -> IO ()
showErr e = do
let err = show e
hPutStrLn stderr $ "git-annex: " ++ err
return ()