2010-10-14 07:40:26 +00:00
|
|
|
{- git-annex main program -}
|
2010-10-10 04:18:16 +00:00
|
|
|
|
2010-10-19 05:46:20 +00:00
|
|
|
import IO (try)
|
2010-10-14 18:38:29 +00:00
|
|
|
import System.IO
|
2010-10-10 22:05:37 +00:00
|
|
|
import System.Environment
|
2010-10-16 20:20:49 +00:00
|
|
|
|
2010-10-14 07:18:11 +00:00
|
|
|
import qualified Annex
|
2010-10-14 18:38:29 +00:00
|
|
|
import Types
|
2010-10-14 07:40:26 +00:00
|
|
|
import Core
|
2010-10-14 18:38:29 +00:00
|
|
|
import Commands
|
2010-10-14 20:13:43 +00:00
|
|
|
import qualified GitRepo as Git
|
2010-10-17 15:47:36 +00:00
|
|
|
import BackendList
|
2010-10-10 04:18:16 +00:00
|
|
|
|
|
|
|
main = do
|
2010-10-10 22:05:37 +00:00
|
|
|
args <- getArgs
|
2010-10-14 20:13:43 +00:00
|
|
|
gitrepo <- Git.repoFromCwd
|
2010-10-17 15:47:36 +00:00
|
|
|
state <- Annex.new gitrepo allBackends
|
2010-10-21 20:30:16 +00:00
|
|
|
(configure, actions) <- parseCmd args state
|
|
|
|
tryRun state $ [startup] ++ configure ++ actions ++ [shutdown]
|
2010-10-14 18:38:29 +00:00
|
|
|
|
2010-10-19 05:46:20 +00:00
|
|
|
{- Runs a list of Annex actions. Catches IO errors and continues
|
|
|
|
- (but explicitly thrown errors terminate the whole command).
|
|
|
|
- Propigates an overall error status at the end.
|
2010-10-14 18:38:29 +00:00
|
|
|
-
|
|
|
|
- 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.
|
|
|
|
-}
|
2010-10-14 18:49:19 +00:00
|
|
|
tryRun :: AnnexState -> [Annex ()] -> IO ()
|
2010-10-14 21:57:04 +00:00
|
|
|
tryRun state actions = tryRun' state 0 actions
|
|
|
|
tryRun' state errnum (a:as) = do
|
2010-10-19 05:46:20 +00:00
|
|
|
result <- try $ Annex.run state a
|
2010-10-14 18:38:29 +00:00
|
|
|
case (result) of
|
|
|
|
Left err -> do
|
|
|
|
showErr err
|
2010-10-14 21:57:04 +00:00
|
|
|
tryRun' state (errnum + 1) as
|
|
|
|
Right (_,state') -> tryRun' state' errnum as
|
|
|
|
tryRun' state errnum [] = do
|
2010-10-14 18:38:29 +00:00
|
|
|
if (errnum > 0)
|
2010-10-14 21:57:04 +00:00
|
|
|
then error $ (show errnum) ++ " failed"
|
2010-10-14 18:38:29 +00:00
|
|
|
else return ()
|
|
|
|
|
|
|
|
{- Exception pretty-printing. -}
|
|
|
|
showErr e = do
|
|
|
|
hPutStrLn stderr $ "git-annex: " ++ (show e)
|
|
|
|
return ()
|