shelly 0.15.1 → 0.15.2
raw patch · 3 files changed
+28/−16 lines, 3 files
Files
- Shelly.hs +24/−13
- Shelly/Base.hs +3/−2
- shelly.cabal +1/−1
Shelly.hs view
@@ -144,6 +144,7 @@ class ShellArg a where toTextArg :: a -> Text instance ShellArg Text where toTextArg = id instance ShellArg FilePath where toTextArg = toTextIgnore+instance ShellArg String where toTextArg = LT.pack -- Voodoo to create the variadic function 'cmd'@@ -151,22 +152,22 @@ cmdAll :: FilePath -> [Text] -> t instance ShellCommand (Sh Text) where- cmdAll fp args = run fp args+ cmdAll = run instance (s ~ Text, Show s) => ShellCommand (Sh s) where- cmdAll fp args = run fp args+ cmdAll = run -- note that Sh () actually doesn't work for its case (_<- cmd) when there is no type signature instance ShellCommand (Sh ()) where- cmdAll fp args = run_ fp args+ cmdAll = run_ instance (ShellArg arg, ShellCommand result) => ShellCommand (arg -> result) where- cmdAll fp acc = \x -> cmdAll fp (acc ++ [toTextArg x])+ cmdAll fp acc x = cmdAll fp (acc ++ [toTextArg x]) -- | variadic argument version of run. -- The syntax is more convenient, but more importantly it also allows the use of a FilePath as a command argument.--- So an argument can be a Text or a FilePath.+-- So an argument can be a Text or a FilePath without manual conversions. -- a FilePath is converted to Text with 'toTextIgnore'. -- You will need to add the following to your module: --@@ -359,13 +360,22 @@ pack :: String -> FilePath pack = decodeString --- | Currently a 'rename' wrapper.--- TODO: Support directory paths in the second parameter, like in 'cp'.+-- | Move a file. The second path could be a directory, in which case the+-- original file is moved into that directory.+-- wraps system-fileio 'FileSystem.rename', which may not work across FS boundaries mv :: FilePath -> FilePath -> Sh ()-mv a b = do a' <- absPath a- b' <- absPath b- trace $ "mv " `mappend` toTextIgnore a' `mappend` " " `mappend` toTextIgnore b'- liftIO $ rename a' b'+mv from' to' = do+ from <- absPath from'+ to <- absPath to'+ trace $ "mv " `mappend` toTextIgnore from `mappend` " " `mappend` toTextIgnore to+ to_dir <- test_d to+ let to_loc = if not to_dir then to else to FP.</> filename from+ liftIO $ rename from to_loc+ `catchany` (\e -> throwIO $+ ReThrownException e (extraMsg to_loc from)+ )+ where+ extraMsg t f = "during copy from: " ++ unpack f ++ " to: " ++ unpack t -- | Get back [Text] instead of [FilePath] lsT :: FilePath -> Sh [Text]@@ -377,7 +387,7 @@ -- | exit 0 means no errors, all other codes are error conditions exit :: Int -> Sh a-exit 0 = liftIO (exitWith ExitSuccess) `tag` "exit 0"+exit 0 = liftIO exitSuccess `tag` "exit 0" exit n = liftIO (exitWith (ExitFailure n)) `tag` ("exit " `mappend` LT.pack (show n)) -- | echo a message and exit with status 1@@ -865,7 +875,7 @@ -- | Pipe operator. set the stdout the first command as the stdin of the second. -- This does not create a shell-level pipe, but hopefully it will in the future.--- To create a shell level pipe you can always set @escaping False@ and use a pipe @|@ character in a command.+-- To create a shell level pipe you can set @escaping False@ and use a pipe @|@ character in a command. (-|-) :: Sh Text -> Sh b -> Sh b one -|- two = do res <- print_stdout False one@@ -873,6 +883,7 @@ two -- | Copy a file, or a directory recursively.+-- uses 'cp' cp_r :: FilePath -> FilePath -> Sh () cp_r from' to' = do from <- absPath from'
Shelly/Base.hs view
@@ -1,7 +1,8 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}--- | prevent circular dependencies--- needed by multiple exposed modules+-- | I started exposing multiple module (starting with one for finding)+-- Base prevented circular dependencies+-- However, Shelly went back to exposing a single module module Shelly.Base ( ShIO, Sh, unSh, runSh, State(..), FilePath, Text,
shelly.cabal view
@@ -1,6 +1,6 @@ Name: shelly -Version: 0.15.1+Version: 0.15.2 Synopsis: shell-like (systems) programming in Haskell Description: Shelly provides convenient systems programming in Haskell,