aboutsummaryrefslogtreecommitdiff
path: root/Command/Info.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-01-15 15:56:47 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-01-15 15:56:47 -0400
commit74f0a01c083b903497476995809a2a65b9911cc4 (patch)
treefe34ae7e145d015532bb0be683a8e1963fc018a6 /Command/Info.hs
parent6979ebdbd1f501344431e2d556e196dc5f5652bf (diff)
info: Support --batch mode.
Diffstat (limited to 'Command/Info.hs')
-rw-r--r--Command/Info.hs18
1 files changed, 15 insertions, 3 deletions
diff --git a/Command/Info.hs b/Command/Info.hs
index 8816ecbcf..426a1300b 100644
--- a/Command/Info.hs
+++ b/Command/Info.hs
@@ -38,6 +38,7 @@ import qualified Limit
import Messages.JSON (DualDisp(..))
import Annex.BloomFilter
import qualified Command.Unused
+import CmdLine.Batch
-- a named computation that produces a statistic
type Stat = StatState (Maybe (String, StatState String))
@@ -86,6 +87,7 @@ cmd = noCommit $ withGlobalOptions (jsonOption : annexedMatchingOptions) $
data InfoOptions = InfoOptions
{ infoFor :: CmdParams
, bytesOption :: Bool
+ , batchOption :: BatchMode
}
optParser :: CmdParamsDesc -> Parser InfoOptions
@@ -95,9 +97,12 @@ optParser desc = InfoOptions
( long "bytes"
<> help "display file sizes in bytes"
)
+ <*> parseBatchOption
seek :: InfoOptions -> CommandSeek
-seek o = withWords (start o) (infoFor o)
+seek o = case batchOption o of
+ NoBatch -> withWords (start o) (infoFor o)
+ Batch -> batchInput Right (itemInfo o)
start :: InfoOptions -> [String] -> CommandStart
start o [] = do
@@ -125,11 +130,18 @@ itemInfo o p = ifM (isdir p)
v' <- Remote.nameToUUID' p
case v' of
Right u -> uuidInfo o u
- Left _ -> ifAnnexed p (fileInfo o p) noinfo
+ Left _ -> ifAnnexed p
+ (fileInfo o p)
+ (noInfo p)
)
where
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
- noinfo = error $ p ++ " is not a directory or an annexed file or a remote or a uuid"
+
+noInfo :: String -> Annex ()
+noInfo s = do
+ showStart "info" s
+ showNote $ " not a directory or an annexed file or a remote or a uuid"
+ showEndFail
dirInfo :: InfoOptions -> FilePath -> Annex ()
dirInfo o dir = showCustom (unwords ["info", dir]) $ do