From d9031e8767ab0eedbd8dbe677edf5bfdeb6dfedf Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Sat, 9 Mar 2024 14:25:05 +0100 Subject: chore: support json output --- src/Process/Shell.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') 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 -- cgit v1.2.3