diff options
author | Joey Hess <joey@kitenet.net> | 2011-10-27 18:56:54 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-10-27 18:56:54 -0400 |
commit | b955238ec7464b12c793d543fc51308c8b213e08 (patch) | |
tree | a8953c64f6933fe233993b29f2a64cf45a850e48 /Command.hs | |
parent | c879eb873ec2fda1ec7d76c0de27d9ace57ba6e7 (diff) |
Fail if --from or --to is passed to commands that do not support them.
Diffstat (limited to 'Command.hs')
-rw-r--r-- | Command.hs | 32 |
1 files changed, 22 insertions, 10 deletions
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" |