aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--anissue.cabal1
-rw-r--r--app/Issue.hs1
-rw-r--r--app/Main.hs23
-rw-r--r--app/Process.hs25
4 files changed, 29 insertions, 21 deletions
diff --git a/anissue.cabal b/anissue.cabal
index 8c84822..56eefd0 100644
--- a/anissue.cabal
+++ b/anissue.cabal
@@ -70,6 +70,7 @@ executable anissue
Issue.Filter
Issue.Tag
Issue.Text
+ Process
TreeGrepper.FileType
TreeGrepper.Match
TreeGrepper.Result
diff --git a/app/Issue.hs b/app/Issue.hs
index ab47ba5..2674a7c 100644
--- a/app/Issue.hs
+++ b/app/Issue.hs
@@ -16,6 +16,7 @@ import TreeGrepper.Match qualified as G
import TreeGrepper.Result (Result (..))
import TreeGrepper.Result qualified as G
import Prelude hiding (id)
+import Process qualified as P
data Issue = Issue
{ title :: Text,
diff --git a/app/Main.hs b/app/Main.hs
index 9e25025..bfe634c 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -72,9 +72,8 @@
module Main where
-import Control.Exception (Exception, catch, handle, throw, throwIO)
+import Control.Exception (Exception, catch, handle, throw)
import Data.Aeson qualified as A
-import Data.ByteString.Lazy qualified as L
import Data.ByteString.Lazy.Char8 qualified as L8
import Data.List (find, intercalate)
import Data.Maybe (catMaybes, fromMaybe)
@@ -89,6 +88,7 @@ import Options.Applicative ((<**>))
import Options.Applicative qualified as O
import Prettyprinter qualified as P
import Prettyprinter.Render.Terminal qualified as P
+import Process (sh, sh_)
import System.Exit (ExitCode (ExitFailure), exitWith)
import System.FilePath qualified as F
import System.Process.Typed qualified as P
@@ -300,25 +300,6 @@ getIssues filename =
)
)
-data ProcessException = ProcessException String ExitCode L.ByteString
- deriving (Show)
-
-instance Exception ProcessException
-
-sh :: P.ProcessConfig stdin stdoutIgnored stderr -> IO L.ByteString
-sh proc = do
- (exitCode, out, err) <- P.readProcess proc
- if exitCode == P.ExitSuccess
- then pure out
- else throwIO $ ProcessException (show proc) exitCode err
-
-sh_ :: P.ProcessConfig stdin stdoutIgnored stderr -> IO ()
-sh_ proc = do
- (exitCode, err) <- P.readProcessStderr proc
- if exitCode == P.ExitSuccess
- then pure ()
- else throwIO $ ProcessException (show proc) exitCode err
-
fixTreeGrepper :: G.Result -> G.Result
fixTreeGrepper treeGrepperResult =
treeGrepperResult {G.matches = G.merge treeGrepperResult.matches}
diff --git a/app/Process.hs b/app/Process.hs
new file mode 100644
index 0000000..39132d4
--- /dev/null
+++ b/app/Process.hs
@@ -0,0 +1,25 @@
+module Process (sh, sh_, quote) where
+
+import Control.Exception (Exception, throwIO)
+import Data.ByteString.Lazy (ByteString)
+import System.Exit (ExitCode (ExitSuccess))
+import System.Process.Typed (ProcessConfig, readProcess, readProcessStderr)
+
+data ProcessException = ProcessException String ExitCode ByteString
+ deriving (Show)
+
+instance Exception ProcessException
+
+sh :: ProcessConfig stdin stdoutIgnored stderr -> IO ByteString
+sh proc = do
+ (exitCode, out, err) <- readProcess proc
+ if exitCode == ExitSuccess
+ then pure out
+ else throwIO $ ProcessException (show proc) exitCode err
+
+sh_ :: ProcessConfig stdin stdoutIgnored stderr -> IO ()
+sh_ proc = do
+ (exitCode, err) <- readProcessStderr proc
+ if exitCode == ExitSuccess
+ then pure ()
+ else throwIO $ ProcessException (show proc) exitCode err