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:
This commit is contained in:
Joey Hess 2016-03-06 12:56:39 -04:00
parent 78fa865721
commit acf74ae945
Failed to extract signature
2 changed files with 14 additions and 9 deletions

View file

@ -54,12 +54,12 @@ import Types.Key
import qualified Annex import qualified Annex
showStart :: String -> FilePath -> 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 ++ " " command ++ " " ++ file ++ " "
showStart' :: String -> Key -> Maybe FilePath -> Annex () showStart' :: String -> Key -> Maybe FilePath -> Annex ()
showStart' command key afile = showStart command $ showStart' command key afile = outputMessage (JSON.start command afile (Just key)) $
fromMaybe (key2file key) afile command ++ " " ++ fromMaybe (key2file key) afile ++ " "
showNote :: String -> Annex () showNote :: String -> Annex ()
showNote s = outputMessage (JSON.note s) $ "(" ++ s ++ ") " showNote s = outputMessage (JSON.note s) $ "(" ++ s ++ ") "
@ -166,7 +166,7 @@ showFullJSON v = withOutputType $ liftIO . go
-} -}
showCustom :: String -> Annex Bool -> Annex () showCustom :: String -> Annex Bool -> Annex ()
showCustom command a = do showCustom command a = do
outputMessage (JSON.start command Nothing) "" outputMessage (JSON.start command Nothing Nothing) ""
r <- a r <- a
outputMessage (JSON.end r) "" outputMessage (JSON.end r) ""

View file

@ -17,13 +17,18 @@ module Messages.JSON (
import Text.JSON import Text.JSON
import qualified Utility.JSONStream as Stream import qualified Utility.JSONStream as Stream
import Types.Key
import Data.Maybe
start :: String -> Maybe String -> IO () start :: String -> Maybe FilePath -> Maybe Key -> IO ()
start command file = start command file key = putStr $ Stream.start $ catMaybes
putStr $ Stream.start $ ("command", command) : filepart file [ part "command" (Just command)
, part "file" file
, part "key" (fmap key2file key)
]
where where
filepart Nothing = [] part _ Nothing = Nothing
filepart (Just f) = [("file", f)] part l (Just v) = Just (l, v)
end :: Bool -> IO () end :: Bool -> IO ()
end b = putStr $ Stream.add [("success", b)] ++ Stream.end end b = putStr $ Stream.add [("success", b)] ++ Stream.end