From b955238ec7464b12c793d543fc51308c8b213e08 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 27 Oct 2011 18:56:54 -0400 Subject: Fail if --from or --to is passed to commands that do not support them. --- Command.hs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'Command.hs') diff --git a/Command.hs b/Command.hs index d19dad260..5690118c4 100644 --- a/Command.hs +++ b/Command.hs @@ -22,8 +22,8 @@ import Init {- A command runs in these stages. - - - a. The check stage is run once and should error out if anything - - prevents the command from running. -} + - a. The check stage runs checks, that error out if + - anything prevents the command from running. -} type CommandCheck = Annex () {- b. The seek stage takes the parameters passed to the command, - looks through the repo to find the ones that are relevant @@ -58,14 +58,6 @@ next a = return $ Just a stop :: Annex (Maybe a) stop = return Nothing -needsNothing :: CommandCheck -needsNothing = return () - -{- Most commands will check this, as they need to be run in an initialized - - repo. -} -needsRepo :: CommandCheck -needsRepo = ensureInitialized - {- Checks that the command can be run in the current environment. -} checkCommand :: Command -> Annex () checkCommand Command { cmdcheck = check } = check @@ -239,3 +231,23 @@ autoCopies key vs numcopiesattr a = do (_, have) <- trustPartition UnTrusted =<< keyLocations key if length have `vs` needed then a else stop else a + +{- Checks -} +defaultChecks :: CommandCheck +defaultChecks = noFrom >> noTo >> needsRepo + +noChecks :: CommandCheck +noChecks = return () + +needsRepo :: CommandCheck +needsRepo = ensureInitialized + +noFrom :: CommandCheck +noFrom = do + v <- Annex.getState Annex.fromremote + unless (v == Nothing) $ error "cannot use --from with this command" + +noTo :: CommandCheck +noTo = do + v <- Annex.getState Annex.toremote + unless (v == Nothing) $ error "cannot use --to with this command" -- cgit v1.2.3