Skip to content

Commit

Permalink
stop using Shellmet in Git.hs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arya Irani committed Feb 13, 2022
1 parent 349de0c commit c77288c
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion parser-typechecker/src/Unison/Codebase/Editor/Git.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Control.Monad.Except (MonadError, throwError)
import qualified Data.ByteString.Base16 as ByteString
import qualified Data.Char as Char
import qualified Data.Text as Text
import Shellmet (($?), ($^), ($|))
import System.Exit (ExitCode (ExitSuccess))
import System.FilePath ((</>))
import System.IO.Unsafe (unsafePerformIO)
Expand Down Expand Up @@ -307,3 +306,38 @@ gitTextIn :: MonadIO m => GitRepo -> [Text] -> m Text
gitTextIn localPath args = do
when debugGit $ traceM (Text.unpack . Text.unwords $ ["$ git"] <> setupGitDir localPath <> args)
liftIO $ "git" $| setupGitDir localPath <> args

-- copying the Shellmet API for now; we can rename or change it up later

{- | This operator runs shell command with given options but doesn't print the
command itself.
>>> "echo" $^ ["Foo", "Bar"]
Foo Bar
-}
infix 5 $^
($^) :: MonadIO m => FilePath -> [Text] -> m ()
cmd $^ args = UnliftIO.callProcess cmd (map Text.unpack args)

{- | Run shell command with given options and return stripped stdout of the
executed command.
>>> "echo" $| ["Foo", "Bar"]
"Foo Bar"
-}
infix 5 $|
($|) :: MonadIO m => FilePath -> [Text] -> m Text
cmd $| args = post <$> UnliftIO.readProcess cmd (map Text.unpack args) stdin
where
stdin = ""
post = Text.strip . Text.pack

{- | Do some IO actions when process failed with 'IOError'.
>>> "exit" ["0"] $? putStrLn "Command failed"
⚙ exit 0
>>> "exit" ["1"] $? putStrLn "Command failed"
⚙ exit 1
Command failed
-}
infixl 4 $?
($?) :: IO a -> IO a -> IO a
action $? handler = action `UnliftIO.catch` \(_ :: IOError) -> handler
{-# INLINE ($?) #-}

0 comments on commit c77288c

Please sign in to comment.