turtle 1.5.21 → 1.5.22
raw patch · 3 files changed
+30/−16 lines, 3 files
Files
- CHANGELOG.md +5/−0
- src/Turtle/Prelude.hs +23/−14
- turtle.cabal +2/−2
CHANGELOG.md view
@@ -1,3 +1,8 @@+1.5.22++* Add new `update` utility+* Improve documentation for `limit`+ 1.5.21 * Build against `optparse-applicative-0.16.0.0`
src/Turtle/Prelude.hs view
@@ -191,6 +191,7 @@ , inplacePrefix , inplaceSuffix , inplaceEntire+ , update , find , findtree , yes@@ -1696,32 +1697,36 @@ -- | Like `sed`, but operates in place on a `FilePath` (analogous to @sed -i@) inplace :: MonadIO io => Pattern Text -> FilePath -> io ()-inplace = inplaceWith sed+inplace = update . sed -- | Like `sedPrefix`, but operates in place on a `FilePath` inplacePrefix :: MonadIO io => Pattern Text -> FilePath -> io ()-inplacePrefix = inplaceWith sedPrefix+inplacePrefix = update . sedPrefix -- | Like `sedSuffix`, but operates in place on a `FilePath` inplaceSuffix :: MonadIO io => Pattern Text -> FilePath -> io ()-inplaceSuffix = inplaceWith sedSuffix+inplaceSuffix = update . sedSuffix -- | Like `sedEntire`, but operates in place on a `FilePath` inplaceEntire :: MonadIO io => Pattern Text -> FilePath -> io ()-inplaceEntire = inplaceWith sedEntire+inplaceEntire = update . sedEntire -inplaceWith- :: MonadIO io- => (Pattern Text -> Shell Line -> Shell Line)- -> Pattern Text- -> FilePath- -> io ()-inplaceWith sed_ pattern' file = liftIO (runManaged (do- here <- pwd+{-| Update a file in place using a `Shell` transformation++ For example, this is used to implement the @inplace*@ family of utilities+-}+update :: MonadIO io => (Shell Line -> Shell Line) -> FilePath -> io ()+update f file = liftIO (runManaged (do+ here <- pwd+ (tmpfile, handle) <- mktemp here "turtle"- outhandle handle (sed_ pattern' (input file))++ outhandle handle (f (input file))+ liftIO (hClose handle)+ copymod file tmpfile+ mv tmpfile file )) -- | Search a directory recursively for all files matching the given `Pattern`@@ -1854,7 +1859,11 @@ loop $! x' loop $! begin ) --- | Limit a `Shell` to a fixed number of values+{-| Limit a `Shell` to a fixed number of values++ NOTE: This is not lazy and will still consume the entire input stream.+ There is no way to implement a lazy version of this utility.+-} limit :: Int -> Shell a -> Shell a limit n s = Shell (\(FoldShell step begin done) -> do ref <- newIORef 0 -- I feel so dirty
turtle.cabal view
@@ -1,5 +1,5 @@ Name: turtle-Version: 1.5.21+Version: 1.5.22 Cabal-Version: >=1.10 Build-Type: Simple License: BSD3@@ -101,7 +101,7 @@ Default-Language: Haskell2010 Build-Depends: base >= 4 && < 5 ,- doctest >= 0.7 && < 0.18+ doctest >= 0.7 && < 0.19 test-suite regression-broken-pipe Type: exitcode-stdio-1.0