summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-03-06 12:56:39 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-03-06 12:57:24 -0400
commitbc6c152e48af37fa570b2ebf0352b1b1206eaecd (patch)
tree67d7cc0f39a8010e8aca5acc7ee30ff7d8b6e47f
parent9c80035727bddc2af69fb9cab41dbf965fe496ec (diff)
improve json when showStart' is given only a key
Before, the json contained file:key; change that to key: If a file and a key are given, inclue both file: and key:
-rw-r--r--Messages.hs8
-rw-r--r--Messages/JSON.hs17
2 files changed, 15 insertions, 10 deletions
diff --git a/Messages.hs b/Messages.hs
index 8d8f916ce..57541cfc0 100644
--- a/Messages.hs
+++ b/Messages.hs
@@ -54,12 +54,12 @@ import Types.Key
import qualified Annex
showStart :: String -> FilePath -> Annex ()
-showStart command file = outputMessage (JSON.start command $ Just file) $
+showStart command file = outputMessage (JSON.start command (Just file) Nothing) $
command ++ " " ++ file ++ " "
showStart' :: String -> Key -> Maybe FilePath -> Annex ()
-showStart' command key afile = showStart command $
- fromMaybe (key2file key) afile
+showStart' command key afile = outputMessage (JSON.start command afile (Just key)) $
+ command ++ " " ++ fromMaybe (key2file key) afile ++ " "
showNote :: String -> Annex ()
showNote s = outputMessage (JSON.note s) $ "(" ++ s ++ ") "
@@ -166,7 +166,7 @@ showFullJSON v = withOutputType $ liftIO . go
-}
showCustom :: String -> Annex Bool -> Annex ()
showCustom command a = do
- outputMessage (JSON.start command Nothing) ""
+ outputMessage (JSON.start command Nothing Nothing) ""
r <- a
outputMessage (JSON.end r) ""
diff --git a/Messages/JSON.hs b/Messages/JSON.hs
index be3dbbc58..fa829a76c 100644
--- a/Messages/JSON.hs
+++ b/Messages/JSON.hs
@@ -17,13 +17,18 @@ module Messages.JSON (
import Text.JSON
import qualified Utility.JSONStream as Stream
-
-start :: String -> Maybe String -> IO ()
-start command file =
- putStr $ Stream.start $ ("command", command) : filepart file
+import Types.Key
+import Data.Maybe
+
+start :: String -> Maybe FilePath -> Maybe Key -> IO ()
+start command file key = putStr $ Stream.start $ catMaybes
+ [ part "command" (Just command)
+ , part "file" file
+ , part "key" (fmap key2file key)
+ ]
where
- filepart Nothing = []
- filepart (Just f) = [("file", f)]
+ part _ Nothing = Nothing
+ part l (Just v) = Just (l, v)
end :: Bool -> IO ()
end b = putStr $ Stream.add [("success", b)] ++ Stream.end