From f97c783283847c6cc4516673fe638b4d551e671d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 29 Oct 2011 15:19:05 -0400 Subject: clean up check selection code This new approach allows filtering out checks from the default set that are not appropriate for a command, rather than having to list every check that is appropriate. It also reduces some boilerplate. Haskell does not define Eq for functions, so I had to go a long way around with each check having a unique id. Meh. --- Command/Add.hs | 4 ++-- Command/AddUrl.hs | 5 ++--- Command/ConfigList.hs | 6 +++--- Command/Copy.hs | 5 +++-- Command/Describe.hs | 4 ++-- Command/Drop.hs | 4 ++-- Command/DropKey.hs | 4 ++-- Command/DropUnused.hs | 4 ++-- Command/Find.hs | 4 ++-- Command/Fix.hs | 4 ++-- Command/FromKey.hs | 5 ++--- Command/Fsck.hs | 4 ++-- Command/Get.hs | 6 +++--- Command/InAnnex.hs | 6 +++--- Command/Init.hs | 5 +++-- Command/InitRemote.hs | 8 ++++---- Command/Lock.hs | 4 ++-- Command/Map.hs | 6 +++--- Command/Merge.hs | 4 ++-- Command/Migrate.hs | 5 ++--- Command/Move.hs | 5 +++-- Command/PreCommit.hs | 5 ++--- Command/RecvKey.hs | 4 ++-- Command/Semitrust.hs | 4 ++-- Command/SendKey.hs | 4 ++-- Command/SetKey.hs | 4 ++-- Command/Status.hs | 4 ++-- Command/Trust.hs | 5 ++--- Command/Unannex.hs | 5 ++--- Command/Uninit.hs | 4 ++-- Command/Unlock.hs | 6 +++--- Command/Untrust.hs | 4 ++-- Command/Unused.hs | 4 ++-- Command/Upgrade.hs | 6 +++--- Command/Version.hs | 5 +++-- Command/Whereis.hs | 4 ++-- 36 files changed, 84 insertions(+), 86 deletions(-) (limited to 'Command') diff --git a/Command/Add.hs b/Command/Add.hs index 33b636bed..82287be0b 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -18,8 +18,8 @@ import Annex.Content import Utility.Touch import Backend -command :: [Command] -command = [Command "add" paramPaths defaultChecks seek "add files to annex"] +def :: [Command] +def = [command "add" paramPaths seek "add files to annex"] {- Add acts on both files not checked into git yet, and unlocked files. -} seek :: [CommandSeek] diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 72e29ff60..e974d06a1 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -19,9 +19,8 @@ import qualified Backend.URL import Annex.Content import Logs.Web -command :: [Command] -command = [Command "addurl" (paramRepeating paramUrl) defaultChecks seek - "add urls to annex"] +def :: [Command] +def = [command "addurl" (paramRepeating paramUrl) seek "add urls to annex"] seek :: [CommandSeek] seek = [withStrings start] diff --git a/Command/ConfigList.hs b/Command/ConfigList.hs index 645d1523c..cbc6e801b 100644 --- a/Command/ConfigList.hs +++ b/Command/ConfigList.hs @@ -11,9 +11,9 @@ import Common.Annex import Command import Annex.UUID -command :: [Command] -command = [Command "configlist" paramNothing defaultChecks seek - "outputs relevant git configuration"] +def :: [Command] +def = [command "configlist" paramNothing seek + "outputs relevant git configuration"] seek :: [CommandSeek] seek = [withNothing start] diff --git a/Command/Copy.hs b/Command/Copy.hs index 2f10d981c..8316b7cab 100644 --- a/Command/Copy.hs +++ b/Command/Copy.hs @@ -10,8 +10,9 @@ module Command.Copy where import Command import qualified Command.Move -command :: [Command] -command = [Command "copy" paramPaths needsRepo seek +def :: [Command] +def = [dontCheck toOpt $ dontCheck fromOpt $ + command "copy" paramPaths seek "copy content of files to/from another repository"] seek :: [CommandSeek] diff --git a/Command/Describe.hs b/Command/Describe.hs index cd5da302e..882a0e1bb 100644 --- a/Command/Describe.hs +++ b/Command/Describe.hs @@ -12,8 +12,8 @@ import Command import qualified Remote import Logs.UUID -command :: [Command] -command = [Command "describe" (paramPair paramRemote paramDesc) defaultChecks seek +def :: [Command] +def = [command "describe" (paramPair paramRemote paramDesc) seek "change description of a repository"] seek :: [CommandSeek] diff --git a/Command/Drop.hs b/Command/Drop.hs index 27049fc67..2267bd941 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -17,8 +17,8 @@ import Logs.Trust import Annex.Content import Config -command :: [Command] -command = [Command "drop" paramPaths (noTo >> needsRepo) seek +def :: [Command] +def = [dontCheck fromOpt $ command "drop" paramPaths seek "indicate content of files not currently wanted"] seek :: [CommandSeek] diff --git a/Command/DropKey.hs b/Command/DropKey.hs index 3e666b9ab..d00bb6c83 100644 --- a/Command/DropKey.hs +++ b/Command/DropKey.hs @@ -13,8 +13,8 @@ import qualified Annex import Logs.Location import Annex.Content -command :: [Command] -command = [Command "dropkey" (paramRepeating paramKey) defaultChecks seek +def :: [Command] +def = [command "dropkey" (paramRepeating paramKey) seek "drops annexed content for specified keys"] seek :: [CommandSeek] diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs index 46f2dc9f7..d2eb3df71 100644 --- a/Command/DropUnused.hs +++ b/Command/DropUnused.hs @@ -19,8 +19,8 @@ import Types.Key type UnusedMap = M.Map String Key -command :: [Command] -command = [Command "dropunused" (paramRepeating paramNumber) (noTo >> needsRepo) +def :: [Command] +def = [dontCheck fromOpt $ command "dropunused" (paramRepeating paramNumber) seek "drop unused file content"] seek :: [CommandSeek] diff --git a/Command/Find.hs b/Command/Find.hs index 291904ec0..46364c987 100644 --- a/Command/Find.hs +++ b/Command/Find.hs @@ -12,8 +12,8 @@ import Command import Annex.Content import Limit -command :: [Command] -command = [Command "find" paramPaths defaultChecks seek "lists available files"] +def :: [Command] +def = [command "find" paramPaths seek "lists available files"] seek :: [CommandSeek] seek = [withFilesInGit start] diff --git a/Command/Fix.hs b/Command/Fix.hs index 090558d52..c46ddc7ee 100644 --- a/Command/Fix.hs +++ b/Command/Fix.hs @@ -12,8 +12,8 @@ import Command import qualified Annex.Queue import Annex.Content -command :: [Command] -command = [Command "fix" paramPaths defaultChecks seek +def :: [Command] +def = [command "fix" paramPaths seek "fix up symlinks to point to annexed content"] seek :: [CommandSeek] diff --git a/Command/FromKey.hs b/Command/FromKey.hs index a3e96b20d..fe9b5c96a 100644 --- a/Command/FromKey.hs +++ b/Command/FromKey.hs @@ -13,9 +13,8 @@ import qualified Annex.Queue import Annex.Content import Types.Key -command :: [Command] -command = [Command "fromkey" paramPath defaultChecks seek - "adds a file using a specific key"] +def :: [Command] +def = [command "fromkey" paramPath seek "adds a file using a specific key"] seek :: [CommandSeek] seek = [withFilesMissing start] diff --git a/Command/Fsck.hs b/Command/Fsck.hs index d025095b1..5d2e2ee50 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -20,8 +20,8 @@ import Utility.DataUnits import Utility.FileMode import Config -command :: [Command] -command = [Command "fsck" paramPaths defaultChecks seek "check for problems"] +def :: [Command] +def = [command "fsck" paramPaths seek "check for problems"] seek :: [CommandSeek] seek = [withNumCopies start] diff --git a/Command/Get.hs b/Command/Get.hs index 21ff73bc4..4a0908bdc 100644 --- a/Command/Get.hs +++ b/Command/Get.hs @@ -14,9 +14,9 @@ import qualified Remote import Annex.Content import qualified Command.Move -command :: [Command] -command = [Command "get" paramPaths (noTo >> needsRepo) seek - "make content of annexed files available"] +def :: [Command] +def = [dontCheck fromOpt $ command "get" paramPaths seek + "make content of annexed files available"] seek :: [CommandSeek] seek = [withNumCopies start] diff --git a/Command/InAnnex.hs b/Command/InAnnex.hs index 7a5735b74..9c169d0d7 100644 --- a/Command/InAnnex.hs +++ b/Command/InAnnex.hs @@ -11,9 +11,9 @@ import Common.Annex import Command import Annex.Content -command :: [Command] -command = [Command "inannex" (paramRepeating paramKey) defaultChecks seek - "checks if keys are present in the annex"] +def :: [Command] +def = [command "inannex" (paramRepeating paramKey) seek + "checks if keys are present in the annex"] seek :: [CommandSeek] seek = [withKeys start] diff --git a/Command/Init.hs b/Command/Init.hs index 664643200..e2a6eb7b0 100644 --- a/Command/Init.hs +++ b/Command/Init.hs @@ -13,8 +13,9 @@ import Annex.UUID import Logs.UUID import Init -command :: [Command] -command = [Command "init" paramDesc noChecks seek "initialize git-annex"] +def :: [Command] +def = [dontCheck repoExists $ + command "init" paramDesc seek "initialize git-annex"] seek :: [CommandSeek] seek = [withWords start] diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs index cea1acc8d..4ba5b0787 100644 --- a/Command/InitRemote.hs +++ b/Command/InitRemote.hs @@ -16,10 +16,10 @@ import qualified Logs.Remote import qualified Types.Remote as R import Annex.UUID -command :: [Command] -command = [Command "initremote" - (paramPair paramName $ paramOptional $ paramRepeating paramKeyValue) - defaultChecks seek "sets up a special (non-git) remote"] +def :: [Command] +def = [command "initremote" + (paramPair paramName $ paramOptional $ paramRepeating paramKeyValue) + seek "sets up a special (non-git) remote"] seek :: [CommandSeek] seek = [withWords start] diff --git a/Command/Lock.hs b/Command/Lock.hs index 8f0bd78eb..329fd3eff 100644 --- a/Command/Lock.hs +++ b/Command/Lock.hs @@ -12,8 +12,8 @@ import Command import qualified Annex.Queue import Backend -command :: [Command] -command = [Command "lock" paramPaths defaultChecks seek "undo unlock command"] +def :: [Command] +def = [command "lock" paramPaths seek "undo unlock command"] seek :: [CommandSeek] seek = [withFilesUnlocked start, withFilesUnlockedToBeCommitted start] diff --git a/Command/Map.hs b/Command/Map.hs index 05cc9d794..7e61d2e9e 100644 --- a/Command/Map.hs +++ b/Command/Map.hs @@ -22,9 +22,9 @@ import qualified Utility.Dot as Dot -- a link from the first repository to the second (its remote) data Link = Link Git.Repo Git.Repo -command :: [Command] -command = [Command "map" paramNothing noChecks seek - "generate map of repositories"] +def :: [Command] +def = [dontCheck repoExists $ + command "map" paramNothing seek "generate map of repositories"] seek :: [CommandSeek] seek = [withNothing start] diff --git a/Command/Merge.hs b/Command/Merge.hs index 33d4c8ffc..c1f7e899a 100644 --- a/Command/Merge.hs +++ b/Command/Merge.hs @@ -11,8 +11,8 @@ import Common.Annex import Command import qualified Annex.Branch -command :: [Command] -command = [Command "merge" paramNothing defaultChecks seek +def :: [Command] +def = [command "merge" paramNothing seek "auto-merge remote changes into git-annex branch"] seek :: [CommandSeek] diff --git a/Command/Migrate.hs b/Command/Migrate.hs index ac8f042ba..a68582996 100644 --- a/Command/Migrate.hs +++ b/Command/Migrate.hs @@ -16,9 +16,8 @@ import qualified Command.Add import Backend import Logs.Web -command :: [Command] -command = [Command "migrate" paramPaths defaultChecks seek - "switch data to different backend"] +def :: [Command] +def = [command "migrate" paramPaths seek "switch data to different backend"] seek :: [CommandSeek] seek = [withBackendFilesInGit start] diff --git a/Command/Move.hs b/Command/Move.hs index 2a7402a0d..5a3ea7172 100644 --- a/Command/Move.hs +++ b/Command/Move.hs @@ -15,8 +15,9 @@ import Annex.Content import qualified Remote import Annex.UUID -command :: [Command] -command = [Command "move" paramPaths needsRepo seek +def :: [Command] +def = [dontCheck toOpt $ dontCheck fromOpt $ + command "move" paramPaths seek "move content of files to/from another repository"] seek :: [CommandSeek] diff --git a/Command/PreCommit.hs b/Command/PreCommit.hs index 5dac4f533..1949de113 100644 --- a/Command/PreCommit.hs +++ b/Command/PreCommit.hs @@ -12,9 +12,8 @@ import qualified Command.Add import qualified Command.Fix import Backend -command :: [Command] -command = [Command "pre-commit" paramPaths defaultChecks seek - "run by git pre-commit hook"] +def :: [Command] +def = [command "pre-commit" paramPaths seek "run by git pre-commit hook"] {- The pre-commit hook needs to fix symlinks to all files being committed. - And, it needs to inject unlocked files into the annex. -} diff --git a/Command/RecvKey.hs b/Command/RecvKey.hs index 3415de526..5243fa9d4 100644 --- a/Command/RecvKey.hs +++ b/Command/RecvKey.hs @@ -13,8 +13,8 @@ import CmdLine import Annex.Content import Utility.RsyncFile -command :: [Command] -command = [Command "recvkey" paramKey defaultChecks seek +def :: [Command] +def = [command "recvkey" paramKey seek "runs rsync in server mode to receive content"] seek :: [CommandSeek] diff --git a/Command/Semitrust.hs b/Command/Semitrust.hs index 4f61531ff..f8c306213 100644 --- a/Command/Semitrust.hs +++ b/Command/Semitrust.hs @@ -12,8 +12,8 @@ import Command import qualified Remote import Logs.Trust -command :: [Command] -command = [Command "semitrust" (paramRepeating paramRemote) defaultChecks seek +def :: [Command] +def = [command "semitrust" (paramRepeating paramRemote) seek "return repository to default trust level"] seek :: [CommandSeek] diff --git a/Command/SendKey.hs b/Command/SendKey.hs index 5118a009b..318ea56d0 100644 --- a/Command/SendKey.hs +++ b/Command/SendKey.hs @@ -12,8 +12,8 @@ import Command import Annex.Content import Utility.RsyncFile -command :: [Command] -command = [Command "sendkey" paramKey defaultChecks seek +def :: [Command] +def = [command "sendkey" paramKey seek "runs rsync in server mode to send content"] seek :: [CommandSeek] diff --git a/Command/SetKey.hs b/Command/SetKey.hs index a60f53997..9c31abb08 100644 --- a/Command/SetKey.hs +++ b/Command/SetKey.hs @@ -12,8 +12,8 @@ import Command import Logs.Location import Annex.Content -command :: [Command] -command = [Command "setkey" paramPath defaultChecks seek +def :: [Command] +def = [command "setkey" paramPath seek "sets annexed content for a key using a temp file"] seek :: [CommandSeek] diff --git a/Command/Status.hs b/Command/Status.hs index df79d4a7f..b5f4956db 100644 --- a/Command/Status.hs +++ b/Command/Status.hs @@ -38,8 +38,8 @@ data StatInfo = StatInfo -- a state monad for running Stats in type StatState = StateT StatInfo Annex -command :: [Command] -command = [Command "status" paramNothing defaultChecks seek +def :: [Command] +def = [command "status" paramNothing seek "shows status information about the annex"] seek :: [CommandSeek] diff --git a/Command/Trust.hs b/Command/Trust.hs index 17b689c34..d976b86a8 100644 --- a/Command/Trust.hs +++ b/Command/Trust.hs @@ -12,9 +12,8 @@ import Command import qualified Remote import Logs.Trust -command :: [Command] -command = [Command "trust" (paramRepeating paramRemote) defaultChecks seek - "trust a repository"] +def :: [Command] +def = [command "trust" (paramRepeating paramRemote) seek "trust a repository"] seek :: [CommandSeek] seek = [withWords start] diff --git a/Command/Unannex.hs b/Command/Unannex.hs index b39dc0a5f..825f81939 100644 --- a/Command/Unannex.hs +++ b/Command/Unannex.hs @@ -17,9 +17,8 @@ import Annex.Content import qualified Git import qualified Git.LsFiles as LsFiles -command :: [Command] -command = [Command "unannex" paramPaths defaultChecks seek - "undo accidential add command"] +def :: [Command] +def = [command "unannex" paramPaths seek "undo accidential add command"] seek :: [CommandSeek] seek = [withFilesInGit start] diff --git a/Command/Uninit.hs b/Command/Uninit.hs index b2046ec41..5a6ee0be2 100644 --- a/Command/Uninit.hs +++ b/Command/Uninit.hs @@ -18,8 +18,8 @@ import Init import qualified Annex.Branch import Annex.Content -command :: [Command] -command = [Command "uninit" paramPaths (check >> defaultChecks) seek +def :: [Command] +def = [addCheck check $ command "uninit" paramPaths seek "de-initialize git-annex and clean out repository"] check :: Annex () diff --git a/Command/Unlock.hs b/Command/Unlock.hs index be1d05298..7ecaf0b7f 100644 --- a/Command/Unlock.hs +++ b/Command/Unlock.hs @@ -13,13 +13,13 @@ import Annex.Content import Utility.CopyFile import Utility.FileMode -command :: [Command] -command = +def :: [Command] +def = [ c "unlock" "unlock files for modification" , c "edit" "same as unlock" ] where - c n = Command n paramPaths defaultChecks seek + c n = command n paramPaths seek seek :: [CommandSeek] seek = [withFilesInGit start] diff --git a/Command/Untrust.hs b/Command/Untrust.hs index 5a2505a10..e16040e6b 100644 --- a/Command/Untrust.hs +++ b/Command/Untrust.hs @@ -12,8 +12,8 @@ import Command import qualified Remote import Logs.Trust -command :: [Command] -command = [Command "untrust" (paramRepeating paramRemote) defaultChecks seek +def :: [Command] +def = [command "untrust" (paramRepeating paramRemote) seek "do not trust a repository"] seek :: [CommandSeek] diff --git a/Command/Unused.hs b/Command/Unused.hs index d2b45ed6b..11c3f429e 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -27,8 +27,8 @@ import qualified Remote import qualified Annex.Branch import Annex.CatFile -command :: [Command] -command = [Command "unused" paramNothing (noTo >> needsRepo) seek +def :: [Command] +def = [dontCheck fromOpt $ command "unused" paramNothing seek "look for unused file content"] seek :: [CommandSeek] diff --git a/Command/Upgrade.hs b/Command/Upgrade.hs index 9ca3c8d2b..b39fcd99c 100644 --- a/Command/Upgrade.hs +++ b/Command/Upgrade.hs @@ -12,9 +12,9 @@ import Command import Upgrade import Annex.Version -command :: [Command] -command = [Command "upgrade" paramNothing noChecks seek - "upgrade repository layout"] +def :: [Command] +def = [dontCheck repoExists $ -- because an old version may not seem to exist + command "upgrade" paramNothing seek "upgrade repository layout"] seek :: [CommandSeek] seek = [withNothing start] diff --git a/Command/Version.hs b/Command/Version.hs index 905a48a51..5a45fd77f 100644 --- a/Command/Version.hs +++ b/Command/Version.hs @@ -12,8 +12,9 @@ import Command import qualified Build.SysConfig as SysConfig import Annex.Version -command :: [Command] -command = [Command "version" paramNothing noChecks seek "show version info"] +def :: [Command] +def = [dontCheck repoExists $ + command "version" paramNothing seek "show version info"] seek :: [CommandSeek] seek = [withNothing start] diff --git a/Command/Whereis.hs b/Command/Whereis.hs index 06a894fd3..7799af08c 100644 --- a/Command/Whereis.hs +++ b/Command/Whereis.hs @@ -13,8 +13,8 @@ import Command import Remote import Logs.Trust -command :: [Command] -command = [Command "whereis" paramPaths defaultChecks seek +def :: [Command] +def = [command "whereis" paramPaths seek "lists repositories that have file content"] seek :: [CommandSeek] -- cgit v1.2.3