summaryrefslogtreecommitdiff
path: root/Types/UUID.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2023-05-05 15:29:49 -0400
committerJoey Hess <joeyh@joeyh.name>2023-05-05 15:33:30 -0400
commit365dbc89dc270465bfbf526f7a0f4a5acca4492d (patch)
treea520f6a3f47b9f5cc542a73ed9bd4e72eec4532f /Types/UUID.hs
parent1a9af823bc2e4684148f3a1a1725a7a0fff16d7c (diff)
expire, trust et al, dead, describe: Support --json and --json-error-messages
For expire, the normal output is unchanged, but the --json output includes the uuid in machine parseable form. Which could be very useful for this somewhat obscure command. That needed ActionItemUUID to be implemented, which seemed like a lot of work, but then --- I had been going to skip implementing them for trust, untrust, dead, semitrust, and describe, but putting the uuid in the json is useful information, it tells what uuid git-annex picked given the input. It was not hard to support these once ActionItemUUID was implemented. Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
Diffstat (limited to 'Types/UUID.hs')
-rw-r--r--Types/UUID.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/Types/UUID.hs b/Types/UUID.hs
index 08f7f8b04a..d7e49ff937 100644
--- a/Types/UUID.hs
+++ b/Types/UUID.hs
@@ -1,6 +1,6 @@
{- git-annex UUID type
-
- - Copyright 2011-2019 Joey Hess <id@joeyh.name>
+ - Copyright 2011-2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@@ -10,6 +10,7 @@
module Types.UUID where
import qualified Data.ByteString as B
+import qualified Data.Text as T
import qualified Data.Map as M
import qualified Data.UUID as U
import Data.Maybe
@@ -20,6 +21,7 @@ import qualified Data.Semigroup as Sem
import Git.Types (ConfigValue(..))
import Utility.FileSystemEncoding
import Utility.QuickCheck
+import Utility.Aeson
import qualified Utility.SimpleProtocol as Proto
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
@@ -65,6 +67,18 @@ instance ToUUID ConfigValue where
instance ToUUID U.UUID where
toUUID = toUUID . U.toASCIIBytes
+instance ToJSON' UUID where
+ toJSON' (UUID u) = toJSON' u
+ toJSON' NoUUID = toJSON' ""
+
+instance FromJSON UUID where
+ parseJSON (String t)
+ | isUUID s = pure (toUUID s)
+ | otherwise = mempty
+ where
+ s = T.unpack t
+ parseJSON _ = mempty
+
buildUUID :: UUID -> Builder
buildUUID (UUID b) = byteString b
buildUUID NoUUID = mempty