allow using Aeson for streaming JSON output

Keeping Text.JSON use for now, because it seems a better fit for most of
the commands, which don't use very structured JSON objects, but just output
whatever fields suites them. But this lets Aeson be used when a more
structured data type is available to serialize to JSON.
This commit is contained in:
Joey Hess 2016-07-26 13:30:07 -04:00
parent fdd87d8e55
commit a030d0a8b7
Failed to extract signature
10 changed files with 52 additions and 33 deletions

View file

@ -146,7 +146,7 @@ perform file = do
cleanup :: Key -> Bool -> CommandCleanup
cleanup key hascontent = do
maybeShowJSON [("key", key2file key)]
maybeShowJSON $ JSONObject [("key", key2file key)]
when hascontent $
logStatus key InfoPresent
return True

View file

@ -356,7 +356,7 @@ cleanup u url file key mtmp = case mtmp of
)
where
go = do
maybeShowJSON [("key", key2file key)]
maybeShowJSON $ JSONObject [("key", key2file key)]
when (isJust mtmp) $
logStatus key InfoPresent
setUrlPresent u key url

View file

@ -66,7 +66,7 @@ start o file key = ifM (limited <||> inAnnex key)
showFormatted :: Maybe Utility.Format.Format -> String -> [(String, String)] -> Annex ()
showFormatted format unformatted vars =
unlessM (showFullJSON vars) $
unlessM (showFullJSON $ JSONObject vars) $
case format of
Nothing -> liftIO $ putStrLn unformatted
Just formatter -> liftIO $ putStr $

View file

@ -250,7 +250,7 @@ nostat = return Nothing
json :: JSON j => (j -> String) -> StatState j -> String -> StatState String
json fmt a desc = do
j <- a
lift $ maybeShowJSON [(desc, j)]
lift $ maybeShowJSON $ JSONObject [(desc, j)]
return $ fmt j
nojson :: StatState String -> String -> StatState String
@ -374,7 +374,7 @@ transfer_list :: Stat
transfer_list = stat desc $ nojson $ lift $ do
uuidmap <- Remote.remoteMap id
ts <- getTransfers
maybeShowJSON [(desc, map (uncurry jsonify) ts)]
maybeShowJSON $ JSONObject [(desc, map (uncurry jsonify) ts)]
return $ if null ts
then "none"
else multiLine $

View file

@ -96,7 +96,7 @@ perform now o k = case getSet o of
cleanup :: Key -> CommandCleanup
cleanup k = do
l <- map unwrapmeta . fromMetaData <$> getCurrentMetaData k
maybeShowJSON l
maybeShowJSON (JSONObject l)
showLongNote $ unlines $ concatMap showmeta l
return True
where

View file

@ -43,7 +43,7 @@ displayStatus s = do
let c = statusChar s
absf <- fromRepo $ fromTopFilePath (statusFile s)
f <- liftIO $ relPathCwdToFile absf
unlessM (showFullJSON [("status", [c]), ("file", f)]) $
unlessM (showFullJSON $ JSONObject [("status", [c]), ("file", f)]) $
liftIO $ putStrLn $ [c] ++ " " ++ f
-- Git thinks that present direct mode files are typechanged.