2024-07-22 15:27:06 -07:00
|
|
|
module Sugar where
|
|
|
|
|
|
|
|
import Pure (kill)
|
|
|
|
import Types (Status(..))
|
|
|
|
|
|
|
|
import System.Exit (ExitCode(ExitFailure), exitWith)
|
|
|
|
import System.Process (readProcess)
|
|
|
|
import Control.Exception (SomeException, catch)
|
|
|
|
|
|
|
|
throw :: (Monoid m) => SomeException -> IO m
|
|
|
|
throw e = print e >> return mempty
|
|
|
|
|
|
|
|
continue :: (Status s) => s -> IO () -> IO ()
|
|
|
|
continue e err = (putStrLn . disp) e >> err
|
|
|
|
|
2024-08-01 20:15:32 -07:00
|
|
|
failure :: SomeException -> IO ()
|
|
|
|
failure = print
|
|
|
|
|
2024-07-22 15:27:06 -07:00
|
|
|
destruct :: (Status s) => s -> IO () -> IO () -> IO ()
|
2024-08-01 20:15:32 -07:00
|
|
|
destruct status success unsuccessful
|
2024-07-22 15:27:06 -07:00
|
|
|
| ok status = success
|
2024-08-01 20:15:32 -07:00
|
|
|
| otherwise = continue status unsuccessful
|
2024-07-22 15:27:06 -07:00
|
|
|
|
|
|
|
crash :: IO ()
|
|
|
|
crash = (exitWith . ExitFailure) 1
|
|
|
|
|
|
|
|
exec :: String -> (SomeException -> IO String) -> IO String
|
|
|
|
exec cmd = catch (readProcess "bash" ["-c", cmd] "")
|
|
|
|
|
|
|
|
killall :: [String] -> [IO String]
|
|
|
|
killall = map (dispatch . kill) where dispatch cmd = exec cmd throw
|