diff options
author | Joey Hess <joey@kitenet.net> | 2011-11-16 00:49:09 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-11-16 00:49:09 -0400 |
commit | 2bb6b02948da8a33b2edcd911fcf3c2597b0ee58 (patch) | |
tree | 631f0694c7b5a17064eb66862230ec666e3871a8 /CmdLine.hs | |
parent | 84784e2ca1ababf21342cba36f7e65b4c3cd303b (diff) |
When not run in a git repository, git-annex can still display a usage message, and "git annex version" even works.
Things that sound simple, but are made hard by the Annex monad being built
with the assumption that there will always be a git repo.
Diffstat (limited to 'CmdLine.hs')
-rw-r--r-- | CmdLine.hs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/CmdLine.hs b/CmdLine.hs index af53abc62..78f46a2e3 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -11,7 +11,9 @@ module CmdLine ( shutdown ) where -import System.IO.Error (try) +import qualified System.IO.Error as IO +import qualified Control.Exception as E +import Control.Exception (throw) import System.Console.GetOpt import Common.Annex @@ -25,14 +27,18 @@ type Params = [String] type Flags = [Annex ()] {- Runs the passed command line. -} -dispatch :: Params -> [Command] -> [Option] -> String -> Git.Repo -> IO () -dispatch args cmds options header gitrepo = do +dispatch :: Params -> [Command] -> [Option] -> String -> IO Git.Repo -> IO () +dispatch args cmds options header getgitrepo = do setupConsole - state <- Annex.new gitrepo - (actions, state') <- Annex.run state $ do - sequence_ flags - prepCommand cmd params - tryRun state' cmd $ [startup] ++ actions ++ [shutdown] + r <- E.try getgitrepo :: IO (Either E.SomeException Git.Repo) + case r of + Left e -> maybe (throw e) id (cmdnorepo cmd) + Right g -> do + state <- Annex.new g + (actions, state') <- Annex.run state $ do + sequence_ flags + prepCommand cmd params + tryRun state' cmd $ [startup] ++ actions ++ [shutdown] where (flags, cmd, params) = parseCmd args cmds options header @@ -77,7 +83,7 @@ tryRun' errnum _ cmd [] | otherwise = return () tryRun' errnum state cmd (a:as) = run >>= handle where - run = try $ Annex.run state $ do + run = IO.try $ Annex.run state $ do Annex.Queue.flushWhenFull a handle (Left err) = showerr err >> cont False state |