2010-10-10 04:18:16 +00:00
|
|
|
{- git-annex main program
|
|
|
|
- -}
|
|
|
|
|
2010-10-11 01:00:42 +00:00
|
|
|
import System.IO
|
2010-10-10 22:05:37 +00:00
|
|
|
import System.Environment
|
2010-10-11 01:00:42 +00:00
|
|
|
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
|
2010-10-11 01:00:42 +00:00
|
|
|
(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
|
2010-10-11 01:00:42 +00:00
|
|
|
|
|
|
|
{- 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"
|
2010-10-11 01:00:42 +00:00
|
|
|
else return ()
|
2010-10-11 22:39:09 +00:00
|
|
|
tryRun errnum oknum (a:as) = do
|
2010-10-11 01:00:42 +00:00
|
|
|
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
|
2010-10-11 01:00:42 +00:00
|
|
|
|
|
|
|
{- Exception pretty-printing. -}
|
|
|
|
showErr :: SomeException -> IO ()
|
|
|
|
showErr e = do
|
|
|
|
let err = show e
|
|
|
|
hPutStrLn stderr $ "git-annex: " ++ err
|
|
|
|
return ()
|