| otherwise -> liftIO $ flushed $ S.putStr msg
JSONOutput _ -> void $ jsonoutputter jsonbuilder s
QuietOutput -> q
- SerializedOutput -> liftIO $ outputSerialized $ OutputMessage (decodeBS' msg)
+ SerializedOutput -> do
+ liftIO $ outputSerialized $ OutputMessage msg
+ void $ jsonoutputter jsonbuilder s
-- Buffer changes to JSON until end is reached and then emit it.
bufferJSON :: JSONBuilder -> MessageState -> Annex Bool
bufferJSON jsonbuilder s = case outputType s of
- JSONOutput jsonoptions
- | endjson -> do
+ JSONOutput _ -> go (flushed . JSON.emit)
+ SerializedOutput -> go (outputSerialized . JSONObject . JSON.encode)
+ _ -> return False
+ where
+ go emitter
+ | endjson = do
Annex.changeState $ \st ->
st { Annex.output = s { jsonBuffer = Nothing } }
- maybe noop (liftIO . flushed . JSON.emit . JSON.finalize jsonoptions) json
+ maybe noop (liftIO . emitter . JSON.finalize) json
return True
- | otherwise -> do
+ | otherwise = do
Annex.changeState $ \st ->
st { Annex.output = s { jsonBuffer = json } }
return True
- _ -> return False
- where
+
(json, endjson) = case jsonbuilder i of
Nothing -> (jsonBuffer s, False)
(Just (j, e)) -> (Just j, e)
+
i = case jsonBuffer s of
Nothing -> Nothing
Just b -> Just (b, False)
-- Immediately output JSON.
outputJSON :: JSONBuilder -> MessageState -> Annex Bool
outputJSON jsonbuilder s = case outputType s of
- JSONOutput _ -> do
- maybe noop (liftIO . flushed . JSON.emit)
+ JSONOutput _ -> go (flushed . JSON.emit)
+ SerializedOutput -> go (outputSerialized . JSONObject . JSON.encode)
+ _ -> return False
+ where
+ go emitter = do
+ maybe noop (liftIO . emitter)
(fst <$> jsonbuilder Nothing)
return True
- _ -> return False
outputError :: String -> Annex ()
outputError msg = withMessageState $ \s -> case (outputType s, jsonBuffer s) of
JSONBuilder,
JSONChunk(..),
emit,
+ encode,
none,
start,
end,
import Data.Monoid
import Prelude
-import Types.Messages
import Types.Command (SeekInput(..))
import Key
import Utility.Metered
end b (Just (o, _)) = Just (HM.insert "success" (toJSON' b) o, True)
end _ Nothing = Nothing
-finalize :: JSONOptions -> Object -> Object
-finalize jsonoptions o
- -- Always include error-messages field, even if empty,
- -- to make the json be self-documenting.
- | jsonErrorMessages jsonoptions = addErrorMessage [] o
- | otherwise = o
+-- Always include error-messages field, even if empty,
+-- to make the json be self-documenting.
+finalize :: Object -> Object
+finalize o = addErrorMessage [] o
addErrorMessage :: [String] -> Object -> Object
addErrorMessage msg o =
import Control.Concurrent
import System.Console.Regions (ConsoleRegion)
+import qualified Data.ByteString as S
+import qualified Data.ByteString.Lazy as L
data OutputType
= NormalOutput
}
data SerializedOutput
- = OutputMessage String
+ = OutputMessage S.ByteString
| OutputError String
| ProgressMeter (Maybe Integer) MeterState MeterState
+ | JSONObject L.ByteString
deriving (Show, Read)