{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Summoner.Process
( deleteFile
) where
import Control.Exception (catch)
import System.Directory (removeFile)
import System.Process (callCommand, showCommandForUser)
import Summoner.Ansi (errorMessage)
instance (a ~ Text, b ~ ()) => IsString ([a] -> IO b) where
fromString cmd args = do
let cmdStr = showCommandForUser cmd (map toString args)
putStrLn $ "⚙ " ++ cmdStr
callCommand cmdStr
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)