module HSH.Helpers.Utils where
import HSH
import Text.StringTemplate.Helpers
import Control.Monad.Error
import System.IO.Error
failIf ioP m = do
p <- ioP
if p then fail m else return ()
inPath :: FilePath -> ErrorT String IO ()
inPath p = do
ErrorT $ do
res <- tryS $ runIO $ render1 [("p",p)] $ "which $p$"
case res of
Left _ -> return . Left $
render1 [("p",p)] "$p$ is not in \\$PATH, maybe you need to modify your shell environment"
Right _ -> return . Right $ ()
tryS :: IO a -> IO (Either String a)
tryS ma = do
etRes <- try ma
return $ case etRes of
Left e -> Left $ show e
Right r -> Right r