always include error-messages field when --json-error-messages
Always include error-messages field, even if empty, to make the json be self-documenting. This was a design requirement for --json-error-messages. This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
parent
6583448bab
commit
63ff670cc5
2 changed files with 19 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
{- git-annex command-line JSON output and input
|
||||
-
|
||||
- Copyright 2011-2016 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2011-2018 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
@ -14,6 +14,7 @@ module Messages.JSON (
|
|||
none,
|
||||
start,
|
||||
end,
|
||||
finalize,
|
||||
note,
|
||||
info,
|
||||
add,
|
||||
|
@ -37,6 +38,7 @@ import Data.Maybe
|
|||
import Data.Monoid
|
||||
import Prelude
|
||||
|
||||
import Types.Messages
|
||||
import Key
|
||||
import Utility.Metered
|
||||
import Utility.Percentage
|
||||
|
@ -74,6 +76,17 @@ end :: Bool -> JSONBuilder
|
|||
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 =
|
||||
HM.insertWith combinearray "error-messages" (Array mempty) o
|
||||
| otherwise = o
|
||||
where
|
||||
combinearray (Array new) (Array old) = Array (old <> new)
|
||||
combinearray new _old = new
|
||||
|
||||
note :: String -> JSONBuilder
|
||||
note _ Nothing = Nothing
|
||||
note s (Just (o, e)) = Just (HM.insertWith combinelines "note" (toJSON s) o, e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue