aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-09 14:25:05 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-09 14:25:05 +0100
commitd9031e8767ab0eedbd8dbe677edf5bfdeb6dfedf (patch)
tree148180e509730769b97fddd7e7763b29c146f31c
parentb0f442b78a6b2c7d8978ae958bcadcc23ff82199 (diff)
chore: support json output
-rw-r--r--sh.cabal1
-rw-r--r--src/Process/Shell.hs12
2 files changed, 13 insertions, 0 deletions
diff --git a/sh.cabal b/sh.cabal
index d5fce58..da19b23 100644
--- a/sh.cabal
+++ b/sh.cabal
@@ -14,6 +14,7 @@ library
default-language: GHC2021
ghc-options: -Wall
build-depends:
+ aeson,
base,
bytestring,
haskell-src-meta,
diff --git a/src/Process/Shell.hs b/src/Process/Shell.hs
index 87d22df..24bea95 100644
--- a/src/Process/Shell.hs
+++ b/src/Process/Shell.hs
@@ -9,11 +9,15 @@
module Process.Shell
( sh,
Quotable (..),
+ ExitCodeException (..),
+ DecodeException (..),
)
where
+import Control.Exception (Exception, throw)
import Control.Monad
import Control.Monad.Reader
+import Data.Aeson
import Data.ByteString qualified as B
import Data.ByteString.Lazy qualified as LB
import Data.ByteString.Lazy.UTF8 qualified as LB
@@ -67,6 +71,14 @@ instance Outputable T.Text where
instance Outputable LT.Text where
fromLBS = LT.decodeUtf8
+data DecodeException = DecodeException
+ deriving (Show)
+
+instance Exception DecodeException
+
+instance (FromJSON a) => Outputable a where
+ fromLBS = fromMaybe (throw DecodeException) . decode
+
class Quotable a where
toString :: a -> String
default toString :: (Show a) => a -> String