From 90a8b38ac048d2a9a7caeb68d70d5148fb4148b8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 14 Feb 2012 12:40:40 -0400 Subject: [PATCH] set oneshot mode on a per-command basis Avoids ugly (and test suite failing) hack in Command.Version --- CmdLine.hs | 6 +++--- Command.hs | 7 ++++++- Command/ConfigList.hs | 2 +- Command/DropKey.hs | 2 +- Command/InAnnex.hs | 2 +- Command/RecvKey.hs | 2 +- Command/SendKey.hs | 2 +- Command/Version.hs | 7 ++----- GitAnnex.hs | 2 +- Types/Command.hs | 1 + git-annex-shell.hs | 2 +- 11 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CmdLine.hs b/CmdLine.hs index d2adb71bbd..0bb3459124 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -28,8 +28,8 @@ type Params = [String] type Flags = [Annex ()] {- Runs the passed command line. -} -dispatch :: Bool -> Params -> [Command] -> [Option] -> String -> IO Git.Repo -> IO () -dispatch oneshot args cmds commonoptions header getgitrepo = do +dispatch :: Params -> [Command] -> [Option] -> String -> IO Git.Repo -> IO () +dispatch args cmds commonoptions header getgitrepo = do setupConsole r <- E.try getgitrepo :: IO (Either E.SomeException Git.Repo) case r of @@ -39,7 +39,7 @@ dispatch oneshot args cmds commonoptions header getgitrepo = do (actions, state') <- Annex.run state $ do sequence_ flags prepCommand cmd params - tryRun state' cmd $ [startup] ++ actions ++ [shutdown oneshot] + tryRun state' cmd $ [startup] ++ actions ++ [shutdown $ cmdoneshot cmd] where (flags, cmd, params) = parseCmd args cmds commonoptions header diff --git a/Command.hs b/Command.hs index e7ce335c71..13ea167bbc 100644 --- a/Command.hs +++ b/Command.hs @@ -8,6 +8,7 @@ module Command ( command, noRepo, + oneShot, withOptions, next, stop, @@ -39,7 +40,11 @@ import Annex.CheckAttr {- Generates a normal command -} command :: String -> String -> [CommandSeek] -> String -> Command -command = Command [] Nothing commonChecks +command = Command [] Nothing commonChecks False + +{- Makes a command run in oneshot mode. -} +oneShot :: Command -> Command +oneShot c = c { cmdoneshot = True } {- Adds a fallback action to a command, that will be run if it's used - outside a git repository. -} diff --git a/Command/ConfigList.hs b/Command/ConfigList.hs index dcf4d15093..fc4ba91022 100644 --- a/Command/ConfigList.hs +++ b/Command/ConfigList.hs @@ -12,7 +12,7 @@ import Command import Annex.UUID def :: [Command] -def = [command "configlist" paramNothing seek +def = [oneShot $ command "configlist" paramNothing seek "outputs relevant git configuration"] seek :: [CommandSeek] diff --git a/Command/DropKey.hs b/Command/DropKey.hs index aaaa224661..68fdbfdd96 100644 --- a/Command/DropKey.hs +++ b/Command/DropKey.hs @@ -14,7 +14,7 @@ import Logs.Location import Annex.Content def :: [Command] -def = [command "dropkey" (paramRepeating paramKey) seek +def = [oneShot $ command "dropkey" (paramRepeating paramKey) seek "drops annexed content for specified keys"] seek :: [CommandSeek] diff --git a/Command/InAnnex.hs b/Command/InAnnex.hs index c41f9a92c1..ad0a4d5c7c 100644 --- a/Command/InAnnex.hs +++ b/Command/InAnnex.hs @@ -12,7 +12,7 @@ import Command import Annex.Content def :: [Command] -def = [command "inannex" (paramRepeating paramKey) seek +def = [oneShot $ command "inannex" (paramRepeating paramKey) seek "checks if keys are present in the annex"] seek :: [CommandSeek] diff --git a/Command/RecvKey.hs b/Command/RecvKey.hs index a27a5efdf6..9744a56d4a 100644 --- a/Command/RecvKey.hs +++ b/Command/RecvKey.hs @@ -14,7 +14,7 @@ import Annex.Content import Utility.RsyncFile def :: [Command] -def = [command "recvkey" paramKey seek +def = [oneShot $ command "recvkey" paramKey seek "runs rsync in server mode to receive content"] seek :: [CommandSeek] diff --git a/Command/SendKey.hs b/Command/SendKey.hs index 7b1cd3ecae..686a31caa7 100644 --- a/Command/SendKey.hs +++ b/Command/SendKey.hs @@ -13,7 +13,7 @@ import Annex.Content import Utility.RsyncFile def :: [Command] -def = [command "sendkey" paramKey seek +def = [oneShot $ command "sendkey" paramKey seek "runs rsync in server mode to send content"] seek :: [CommandSeek] diff --git a/Command/Version.hs b/Command/Version.hs index 8761d2a2e0..af08d3d709 100644 --- a/Command/Version.hs +++ b/Command/Version.hs @@ -11,10 +11,9 @@ import Common.Annex import Command import qualified Build.SysConfig as SysConfig import Annex.Version -import CmdLine def :: [Command] -def = [noRepo showPackageVersion $ dontCheck repoExists $ +def = [oneShot $ noRepo showPackageVersion $ dontCheck repoExists $ command "version" paramNothing seek "show version info"] seek :: [CommandSeek] @@ -29,9 +28,7 @@ start = do putStrLn $ "default repository version: " ++ defaultVersion putStrLn $ "supported repository versions: " ++ vs supportedVersions putStrLn $ "upgrade supported from repository versions: " ++ vs upgradableVersions - -- avoid normal cleanup - _ <- shutdown True - liftIO exitSuccess + stop where vs = join " " diff --git a/GitAnnex.hs b/GitAnnex.hs index 1ca89315a3..4af10a9ce4 100644 --- a/GitAnnex.hs +++ b/GitAnnex.hs @@ -129,4 +129,4 @@ header :: String header = "Usage: git-annex command [option ..]" run :: [String] -> IO () -run args = dispatch False args cmds options header Git.Construct.fromCurrent +run args = dispatch args cmds options header Git.Construct.fromCurrent diff --git a/Types/Command.hs b/Types/Command.hs index 1233df2cd9..6dbcf48d16 100644 --- a/Types/Command.hs +++ b/Types/Command.hs @@ -36,6 +36,7 @@ data Command = Command { cmdoptions :: [Option] -- command-specific options , cmdnorepo :: Maybe (IO ()) -- an action to run when not in a repo , cmdcheck :: [CommandCheck] -- check stage + , cmdoneshot :: Bool -- don't save state after running , cmdname :: String , cmdparamdesc :: String -- description of params for usage , cmdseek :: [CommandSeek] -- seek stage diff --git a/git-annex-shell.hs b/git-annex-shell.hs index e747a447b4..4fdeae1a87 100644 --- a/git-annex-shell.hs +++ b/git-annex-shell.hs @@ -82,7 +82,7 @@ builtins = map cmdname cmds builtin :: String -> String -> [String] -> IO () builtin cmd dir params = do checkNotReadOnly cmd - dispatch True (cmd : filterparams params) cmds options header $ + dispatch (cmd : filterparams params) cmds options header $ Git.Construct.repoAbsPath dir >>= Git.Construct.fromAbsPath external :: [String] -> IO ()