shell-conduit 4.0 → 4.1
raw patch · 2 files changed
+22/−5 lines, 2 files
Files
- shell-conduit.cabal +1/−1
- src/Data/Conduit/Shell/Process.hs +21/−4
shell-conduit.cabal view
@@ -1,5 +1,5 @@ name: shell-conduit-version: 4.0+version: 4.1 synopsis: Write shell scripts with Conduit description: Write shell scripts with Conduit. See "Data.Conduit.Shell" for documentation. license: BSD3
src/Data/Conduit/Shell/Process.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE RankNTypes #-}@@ -61,6 +62,21 @@ instance Applicative Segment where (<*>) = ap; pure = return +instance Alternative Segment where+ this <|> that =+ do ex <- tryS this+ case ex of+ Right x -> pure x+ Left (e :: ProcessException) -> that+ empty = throw ProcessEmpty++-- | Try something in a segment.+tryS :: Exception e => Segment r -> Segment (Either e r)+tryS s =+ case s of+ SegmentConduit c -> SegmentConduit (tryC c)+ SegmentProcess f -> SegmentProcess (\h -> try (f h))+ instance MonadIO Segment where liftIO x = SegmentProcess (const x) @@ -69,9 +85,10 @@ Handles Handle Handle Handle -- | Process running exception.-data ProcessException =- ProcessException CreateProcess- ExitCode+data ProcessException+ = ProcessException CreateProcess+ ExitCode+ | ProcessEmpty deriving (Typeable) instance Exception ProcessException@@ -83,7 +100,7 @@ ShellCommand s -> "shell command " ++ show s RawCommand f args -> "raw command: " ++- show (f : args)+ unwords (f : map show args) ," returned a failure exit code: " ,case ec of ExitFailure i -> show i