module HSH.Helpers.Instances where
import HSH
import System.Exit
import System.Posix.Process
instance RunResult (IO (Either String ()) ) where
run cmd = checkResults =<< run cmd
checkResults :: (String, ProcessStatus) -> IO (Either String ())
checkResults (cmd, ps) =
case ps of
Exited (ExitSuccess) -> return $ Right ()
Exited (ExitFailure x) ->
return $ Left $ cmd ++ ": exited with code " ++ show x
Terminated sig ->
return $ Left $ cmd ++ ": terminated by signal " ++ show sig
Stopped sig ->
return $ Left $ cmd ++ ": stopped by signal " ++ show sig