2010-10-10 00:18:16 -04:00
|
|
|
{- git-annex main program
|
|
|
|
- -}
|
|
|
|
|
2010-10-13 21:28:47 -04:00
|
|
|
import Control.Monad.State
|
2010-10-10 21:00:42 -04:00
|
|
|
import System.IO
|
2010-10-10 18:05:37 -04:00
|
|
|
import System.Environment
|
2010-10-10 21:00:42 -04:00
|
|
|
import Control.Exception
|
2010-10-10 18:05:37 -04:00
|
|
|
import CmdLine
|
2010-10-13 21:28:47 -04:00
|
|
|
import Types
|
2010-10-10 15:04:18 -04:00
|
|
|
import Annex
|
2010-10-10 00:18:16 -04:00
|
|
|
|
|
|
|
main = do
|
2010-10-10 18:05:37 -04:00
|
|
|
args <- getArgs
|
2010-10-13 21:28:47 -04:00
|
|
|
(mode, params) <- argvToMode args
|
2010-10-10 18:25:31 -04:00
|
|
|
state <- startAnnex
|
2010-10-13 21:28:47 -04:00
|
|
|
tryRun state mode 0 0 params
|
2010-10-10 12:41:20 -04:00
|
|
|
|
2010-10-13 21:28:47 -04:00
|
|
|
{- Processes each param in the list by dispatching the handler function
|
|
|
|
- for the user-selection operation mode. Catches exceptions, not stopping
|
|
|
|
- if some error out, and propigates an overall error status at the end.
|
|
|
|
-
|
|
|
|
- This runs in the IO monad, not in the Annex monad. It seems that
|
|
|
|
- exceptions can only be caught in the IO monad, not in a stacked monad;
|
|
|
|
- or more likely I missed an easy way to do it. So, I have to laboriously
|
|
|
|
- thread AnnexState through this function.
|
|
|
|
-}
|
|
|
|
tryRun :: AnnexState -> Mode -> Int -> Int -> [String] -> IO ()
|
|
|
|
tryRun state mode errnum oknum [] = do
|
2010-10-11 18:39:09 -04:00
|
|
|
if (errnum > 0)
|
2010-10-11 18:39:36 -04:00
|
|
|
then error $ (show errnum) ++ " failed ; " ++ show (oknum) ++ " ok"
|
2010-10-10 21:00:42 -04:00
|
|
|
else return ()
|
2010-10-13 21:28:47 -04:00
|
|
|
tryRun state mode errnum oknum (f:fs) = do
|
|
|
|
result <- try (runAnnexState state (dispatch mode f))::IO (Either SomeException ((), AnnexState))
|
2010-10-10 21:00:42 -04:00
|
|
|
case (result) of
|
|
|
|
Left err -> do
|
|
|
|
showErr err
|
2010-10-13 21:28:47 -04:00
|
|
|
tryRun state mode (errnum + 1) oknum fs
|
|
|
|
Right (_,state') -> tryRun state' mode errnum (oknum + 1) fs
|
2010-10-10 21:00:42 -04:00
|
|
|
|
|
|
|
{- Exception pretty-printing. -}
|
|
|
|
showErr e = do
|
2010-10-13 16:21:50 -04:00
|
|
|
hPutStrLn stderr $ "git-annex: " ++ (show e)
|
2010-10-10 21:00:42 -04:00
|
|
|
return ()
|