summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-01-20 13:04:07 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-01-20 13:04:07 -0400
commit91c9f6f086cf6d503c3ecb10a211c0c946e554eb (patch)
treea4e5409d432176937b326f6bf9056c440c40dee1 /Command
parentc48b1434d1443ea1421fa474a6a5aecbf60ac83a (diff)
find --batch
Diffstat (limited to 'Command')
-rw-r--r--Command/Find.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/Command/Find.hs b/Command/Find.hs
index ae5595c1d..c720ce76c 100644
--- a/Command/Find.hs
+++ b/Command/Find.hs
@@ -17,6 +17,7 @@ import Limit
import qualified Utility.Format
import Utility.DataUnits
import Types.Key
+import CmdLine.Batch
cmd :: Command
cmd = withGlobalOptions annexedMatchingOptions $ mkCommand $
@@ -29,12 +30,14 @@ mkCommand = noCommit . noMessages . withGlobalOptions [jsonOption]
data FindOptions = FindOptions
{ findThese :: CmdParams
, formatOption :: Maybe Utility.Format.Format
+ , batchOption :: BatchMode
}
optParser :: CmdParamsDesc -> Parser FindOptions
optParser desc = FindOptions
<$> cmdParams desc
<*> optional parseFormatOption
+ <*> parseBatchOption
parseFormatOption :: Parser Utility.Format.Format
parseFormatOption =
@@ -48,15 +51,21 @@ parseFormatOption =
)
seek :: FindOptions -> CommandSeek
-seek o = withFilesInGit (whenAnnexed $ start o) (findThese o)
+seek o = case batchOption o of
+ NoBatch -> withFilesInGit go (findThese o)
+ Batch -> batchFiles go
+ where
+ go = whenAnnexed $ start o
+-- only files inAnnex are shown, unless the user has requested
+-- others via a limit
start :: FindOptions -> FilePath -> Key -> CommandStart
-start o file key = do
- -- only files inAnnex are shown, unless the user has requested
- -- others via a limit
- whenM (limited <||> inAnnex key) $
+start o file key = ifM (limited <||> inAnnex key)
+ ( do
showFormatted (formatOption o) file $ ("file", file) : keyVars key
- stop
+ next $ next $ return True
+ , stop
+ )
showFormatted :: Maybe Utility.Format.Format -> String -> [(String, String)] -> Annex ()
showFormatted format unformatted vars =