{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Summoner.Process
( deleteFile
) where
import Relude
import Control.Exception (catch, displayException)
import System.Directory (removeFile, setCurrentDirectory)
import System.Process (callProcess)
import Summoner.Ansi (errorMessage)
instance (a ~ Text, b ~ ()) => IsString ([a] -> IO b) where
fromString "cd" [arg] = setCurrentDirectory $ toString arg
fromString cmd args = callProcess cmd (map toString args)
deleteFile :: FilePath -> IO ()
deleteFile file = removeFile file `catch` printError
where
printError :: SomeException -> IO ()
printError e = errorMessage $ "Could not delete file '"
<> toText file <> "'. " <> toText (displayException e)