From 805d47c4b5db311601f499732e9492341cdd270c Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 7 Mar 2024 03:57:03 +0100 Subject: chore: run `sh` in `MonadIO` --- src/Process/Shell.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/Process/Shell.hs') diff --git a/src/Process/Shell.hs b/src/Process/Shell.hs index 94ba3c9..63d2f8a 100644 --- a/src/Process/Shell.hs +++ b/src/Process/Shell.hs @@ -11,6 +11,7 @@ module Process.Shell where import Control.Monad +import Control.Monad.Trans import Data.ByteString qualified as B import Data.ByteString.Lazy qualified as LB import Data.ByteString.Lazy.UTF8 qualified as LB @@ -35,21 +36,23 @@ class Processable a r where instance (Processable a r) => Processable (String -> a) (String -> r) where sh_ f x = sh_ (f x) -instance Processable String (IO ()) where +instance (MonadIO m) => Processable String (m ()) where sh_ s = do - runProcess_ (fromString s) + liftIO (runProcess_ (fromString s)) -instance (Outputable a) => Processable String (IO a) where +instance (MonadIO m, Outputable a) => Processable String (m a) where sh_ s = do - fromLBS <$> readProcessInterleaved_ (fromString s) + fromLBS <$> liftIO (readProcessInterleaved_ (fromString s)) -instance (Outputable stdout, Outputable stderr) => Processable String (IO (stdout, stderr)) where +instance (MonadIO m, Outputable stdout, Outputable stderr) => Processable String (m (stdout, stderr)) where sh_ s = do - (\(out, err) -> (fromLBS out, fromLBS err)) <$> readProcess_ (fromString s) + (\(out, err) -> (fromLBS out, fromLBS err)) + <$> liftIO (readProcess_ (fromString s)) -instance (Outputable stdout, Outputable stderr) => Processable String (IO (ExitCode, stdout, stderr)) where +instance (MonadIO m, Outputable stdout, Outputable stderr) => Processable String (m (ExitCode, stdout, stderr)) where sh_ s = do - (\(exitCode, out, err) -> (exitCode, fromLBS out, fromLBS err)) <$> readProcess (fromString s) + (\(exitCode, out, err) -> (exitCode, fromLBS out, fromLBS err)) + <$> liftIO (readProcess (fromString s)) class Outputable a where fromLBS :: LB.ByteString -> a -- cgit v1.2.3