packages feed

pipes-shell 0.1.0 → 0.1.2

raw patch · 2 files changed

+54/−40 lines, 2 filesdep ~basedep ~hspecdep ~pipes-bytestring

Dependency ranges changed: base, hspec, pipes-bytestring, process, text

Files

pipes-shell.cabal view
@@ -4,13 +4,13 @@ -- The name of the package. name:                pipes-shell -version:             0.1.0+version:             0.1.2  -- A short (one-line) description of the package. synopsis:             Create proper Pipes from System.Process  -- A longer description of the package.-description:          This package provide functions to build proper Pipes from Unix shell commands like /tr/, /ls/ or /echo/ in a concise way.+description:          This package provides functions to build proper Pipes from Unix shell commands like /tr/, /ls/ or /echo/ in a concise way.                       .                       Build with /cabal configure --enable-tests/ to build the little hspec test. @@ -59,20 +59,22 @@   -- other-extensions:    -- Other library packages from which modules are imported.-  build-depends:       base >=4.6 && <4.7,-                       stm >=2.4 && <2.5,-                       process >=1.1 && <1.2,-                       pipes >= 4.0.1 && <5,-                       pipes-safe >= 2.0.1 && <3,-                       pipes-bytestring >= 1.0.1 && <2,-                       text >= 0.11.3.0 && <0.12,-                       bytestring >= 0.10.0.2 && <0.11,-                       async >= 2.0.1.0 && <2.1,-                       stm-chans >= 3.0.0 && <3.1+  build-depends:   base >=4.5 && <4.8,+                   stm >=2.4 && <2.5,+                   process >=1.2 && <1.3,+                   pipes >= 4.0.1 && <5,+                   pipes-safe >= 2.0.1 && <3,+                   pipes-bytestring >= 1.0.1 && <3,+                   text >= 0.11.3.0 && <1.2,+                   bytestring >= 0.10.0.2 && <0.11,+                   async >= 2.0.1.0 && <2.1,+                   stm-chans >= 3.0.0 && <3.1    -- Directories containing source files.   hs-source-dirs:      src +  ghc-options:         -O2 -Wall+   -- Base language which the package is written in.   default-language:    Haskell2010 @@ -87,21 +89,21 @@   -- other-extensions:    -- Other library packages from which modules are imported.-  build-depends:   base >=4.6 && <4.7,+  build-depends:   base >=4.5 && <4.8,                    stm >=2.4 && <2.5,-                   process >=1.1 && <1.2,+                   process >=1.2 && <1.3,                    pipes >= 4.0.1 && <5,                    pipes-safe >= 2.0.1 && <3,-                   pipes-bytestring >= 1.0.1 && <2,-                   text >= 0.11.3.0 && <0.12,+                   pipes-bytestring >= 1.0.1 && <3,+                   text >= 0.11.3.0 && <1.2,                    bytestring >= 0.10.0.2 && <0.11,                    async >= 2.0.1.0 && <2.1,                    stm-chans >= 3.0.0 && <3.1,-                   hspec >= 1.7.2.0 && <1.8+                   hspec >= 1.7.2.0 && <1.10    -- Directories containing source files.   hs-source-dirs:  src, test    -- Base language which the package is written in.   default-language:    Haskell2010-  ghc-options:         -Wall+  ghc-options:         -Wall -rtsopts
src/Pipes/Shell.hs view
@@ -1,14 +1,14 @@-{-# LANGUAGE FlexibleContexts          #-}-{-# LANGUAGE FlexibleInstances         #-}-{-# LANGUAGE NoMonomorphismRestriction #-}-{-# LANGUAGE OverlappingInstances      #-}-{-# LANGUAGE RankNTypes                #-}-{-# LANGUAGE TypeFamilies              #-}+{-# LANGUAGE FlexibleInstances    #-}+{-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE Rank2Types #-}  -- | This module contains a few functions to use unix-y shell commands -- as 'Pipe's. ----- The output 'ByteString's from 'pipeCmdEnv' and friends are not line-wise, but chunk-wise. To get proper lines use the pipes-binary and the upcoming pipes-text machinery.+-- The output 'ByteString's from 'pipeCmdEnv' and friends are not line-wise,+-- but chunk-wise. To get proper lines+-- use the pipes-bytestring and the upcoming pipes-text machinery.+-- Note that exit code handling is not yet implemented. -- -- All code examples in this module assume following qualified imports: -- Pipes.Prelude as P, Pipes.ByteString as PBS, Data.ByteString.Char8 as BSC@@ -52,8 +52,8 @@  -- | An ad-hoc typeclass to get the varadic arguments and DWIM behavoir of 'cmdEnv' class Cmd cmd where-  -- | Like 'pipeCmdEnv', 'producerCmdEnv' or 'consumerCmdEnv' depending on the context.-  -- It also supports varadic arguments.+  -- | Like 'pipeCmdEnv', 'producerCmdEnv' or 'consumerCmdEnv'+  -- depending on the context. It also supports varadic arguments.   --   -- Examples:   --@@ -81,15 +81,22 @@   cmdEnv env' binary arg = cmdEnv env' $ binary ++ " " ++ arg  instance MonadSafe m =>-         Cmd (Pipe (Maybe BS.ByteString) (Either BS.ByteString BS.ByteString) m ()) where+         Cmd (Pipe+              (Maybe BS.ByteString)+              (Either BS.ByteString BS.ByteString)+              m ()) where   cmdEnv = pipeCmdEnv  instance MonadSafe m =>-         Cmd (Producer (Either BS.ByteString BS.ByteString) m ()) where+         Cmd (Producer+              (Either BS.ByteString BS.ByteString)+              m ()) where   cmdEnv = producerCmdEnv  instance MonadSafe m =>-         Cmd (Consumer (Maybe BS.ByteString) m ()) where+         Cmd (Consumer+              (Maybe BS.ByteString)+              m ()) where   cmdEnv = consumerCmdEnv  @@ -134,7 +141,7 @@   \(stdin, stdout, stderr) -> do      chan <- liftIO $ newTBMChanIO 4-    _ <- liftIO $ forkIO $+    _ <- liftIO . forkIO $       handlesToChan stdout stderr chan      body stdin chan@@ -208,27 +215,28 @@ -- | Like 'pipeCmd' but closes the output end immediately. -- -- Useful for command line tools like @ cat > test.file @-consumerCmdEnv:: MonadSafe m =>+consumerCmdEnv :: MonadSafe m =>               Maybe [(String,String)] ->               String ->               Consumer (Maybe BS.ByteString) m () consumerCmdEnv env' cmdStr = pipeCmdEnv env' cmdStr >-> void await  -- | Like 'consumerCmdEnv' but doesn't set enviorment varaibles-consumerCmd:: MonadSafe m =>+consumerCmd :: MonadSafe m =>               String ->               Consumer (Maybe BS.ByteString) m () consumerCmd = consumerCmdEnv Nothing - -- Utils  -- | Like '>->' but marks the end of the left pipe with 'markEnd'.--- It's needed because 'pipeCmdEnv' has to know when the upstream 'Pipe' finishes.+-- It's needed because 'pipeCmdEnv' has to know when+-- the upstream 'Pipe' finishes. -- -- The basic rule is: ----- @ Replace every '>->' with '>?>' when it's in front of 'pipeCmdEnv' or similar. @+-- @ Replace every '>->' with '>?>' when it's in front of+--   'pipeCmdEnv' or similar. @ (>?>) :: Monad m =>      Proxy a' a         () b m r ->      Proxy () (Maybe b) c' c m r ->@@ -237,7 +245,8 @@ infixl 7 >?>  -- | Mark the end of a pipe.--- It wraps all values in a 'Just' and yields *one* 'Nothing' after the upstream pipefinished.+-- It wraps all values in a 'Just' and yields *one* 'Nothing'+-- after the upstream pipe finished. markEnd :: Monad m =>            Proxy a' a b' b         m r ->            Proxy a' a b' (Maybe b) m r@@ -247,7 +256,8 @@   return result  -- | Ignore stderr from a 'pipeCmd'-ignoreErr :: (Monad m) => Pipe (Either BS.ByteString BS.ByteString) BS.ByteString m ()+ignoreErr :: (Monad m) =>+             Pipe (Either BS.ByteString BS.ByteString) BS.ByteString m () ignoreErr = forever $ do   val <- await   case val of@@ -272,7 +282,7 @@  whenJust :: Monad m => Maybe a -> (a -> m ()) -> m () whenJust (Just x) action = action x-whenJust Nothing _ = return ()+whenJust Nothing _       = return ()  fromTBMChan :: (MonadIO m) => TBMChan a -> Producer' a m () fromTBMChan chan = do@@ -291,7 +301,8 @@               String ->               m (IO.Handle, IO.Handle, IO.Handle) aquirePipe env' cmdStr = liftIO $ do-  (Just stdin, Just stdout, Just stderr, _) <- createProcess (shellPiped env' cmdStr)+  (Just stdin, Just stdout, Just stderr, _) <-+    createProcess (shellPiped env' cmdStr)   return (stdin, stdout, stderr)  -- | Releases the pipe handles@@ -312,4 +323,5 @@     , std_err      = CreatePipe     , close_fds    = False     , create_group = False+    , delegate_ctlc = False     }