summaryrefslogtreecommitdiff
path: root/git-annex.hs
blob: 7785e4f2d750678d7114328490308d5b8314cb09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{- git-annex main program
 - -}

import System.IO
import System.Environment
import Control.Exception
import CmdLine
import Annex

main = do
	args <- getArgs
	(mode, files) <- argvToMode args
	
	state <- startAnnex

	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. -}
tryRun errnum oknum [] = do
	if (errnum > 0)
		then error $ (show errnum) ++ " failed ; " ++ show (oknum) ++ " ok"
		else return ()
tryRun errnum oknum (a:as) = do
	result <- try (a)::IO (Either SomeException ())
	case (result) of
		Left err -> do
			showErr err
			tryRun (errnum + 1) oknum as
		Right _ -> tryRun errnum (oknum + 1) as

{- Exception pretty-printing. -}
showErr :: SomeException -> IO ()
showErr e = do
	hPutStrLn stderr $ "git-annex: " ++ (show e)
	return ()