shelly 0.5.1 → 0.6
raw patch · 3 files changed
+50/−42 lines, 3 files
Files
- Shelly.hs +35/−38
- shelly.cabal +7/−4
- test/main.hs +8/−0
Shelly.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE ScopedTypeVariables, DeriveDataTypeable, OverloadedStrings,- MultiParamTypeClasses, FlexibleInstances #-}+ MultiParamTypeClasses, FlexibleInstances, TypeSynonymInstances, IncoherentInstances #-} -- | A module for shell-like / perl-like programming in Haskell. -- Shelly's focus is entirely on ease of use for those coming from shell scripting.@@ -11,17 +11,23 @@ -- directory. -- -- I highly recommend putting the following at the top of your program,--- otherwise you will need either type annotations/conversions+-- otherwise you will likely need either type annotations or type conversions ----- {-# LANGUAGE OverloadedStrings #-}--- {-# LANGUAGE ExtendedDefaultRules #-}--- {-# OPTIONS_GHC -fno-warn-type-defaults #-}--- default (Text) -- this goes after import statements+-- > {-# LANGUAGE OverloadedStrings #-}+-- > {-# LANGUAGE ExtendedDefaultRules #-}+-- > {-# OPTIONS_GHC -fno-warn-type-defaults #-}+-- > import Data.Text.Lazy as LT+-- > default (LT.Text) module Shelly ( -- * Entering ShIO. ShIO, shelly, sub, silently, verbosely, print_commands + -- * Running external commands.+ , run, run_, cmd, (-|-), lastStderr, setStdin+ , command, command_, command1, command1_+-- , Sudo(..), run_sudo+ -- * Modifying and querying environment. , setenv, getenv, getenv_def, appendToPath @@ -41,11 +47,6 @@ , mv, rm_f, rm_rf, cp, cp_r, mkdir, mkdir_p , readfile, writefile, appendfile, withTmpDir - -- * Running external commands.- , run, result, ( # ), run_, (-|-), lastStderr, setStdin- , command, command_, command1, command1_--- , Sudo(..), run_sudo- -- * exiting the program , exit, errorExit, terror @@ -54,10 +55,10 @@ , catchany, catch_sh, catchany_sh , MemTime(..), time , RunFailed(..)- -- * mappend (<>) Text with a FilePath- , (|<>), (<>|)+ -- * convert between Text and FilePath , toTextIgnore, toTextWarn, fromText+ -- * Re-exported for your convenience , liftIO, when, unless ) where@@ -115,9 +116,6 @@ import System.PosixCompat.Files( getSymbolicLinkStatus, isSymbolicLink ) import System.Directory ( setPermissions, getPermissions, Permissions(..), getTemporaryDirectory, findExecutable ) -infixr 5 <>| -infixr 5 |<> - {- GHC won't default to Text with this class ShellArgs a where toTextArgs :: a -> [Text]@@ -153,26 +151,36 @@ instance ShellArg FilePath where toTextArg = toTextIgnore --- | For the variadic argument version of 'run' called 'result'.+-- | For the variadic argument version of 'run' called 'cmd'. class ShellCommand t where cmdAll :: FilePath -> [Text] -> t+ instance ShellCommand (ShIO Text) where cmdAll fp args = run fp args-instance ShellCommand (ShIO ()) where- cmdAll fp args = run_ fp args++-- note that ShIO () actually doesn't compile all the time!+instance ShellCommand (ShIO a) where+ cmdAll fp args = run_ fp args >>+ return (error "No Way! Shelly did not see this coming. Please report this error.")+ instance (ShellArg arg, ShellCommand result) => ShellCommand (arg -> result) where cmdAll fp acc = \x -> cmdAll fp (acc ++ [toTextArg x]) -- | variadic argument version of run.--- Convenient (avoid list syntax and use FilePath without converting), but has a big downside:--- It always returns a result, it should always be used as value <- result--- Note that value could be ().--- If you do not return a value you will get a nasty error message!--- So the function is named 'result' to remind you of that.+-- The syntax is more convenient but it also allows the use of a FilePath as an argument. -- An argument can be a Text or a FilePath. -- a FilePath is converted to Text with 'toTextIgnore'.-result :: (ShellCommand result) => FilePath -> result-result fp = cmdAll fp []+-- You will need to add the following to your module:+--+-- > {-# LANGUAGE OverloadedStrings #-}+-- > {-# LANGUAGE ExtendedDefaultRules #-}+-- > {-# OPTIONS_GHC -fno-warn-type-defaults #-}+-- > import Shelly+-- > import Data.Text.Lazy as LT+-- > default (LT.Text)+--+cmd :: (ShellCommand result) => FilePath -> result+cmd fp = cmdAll fp [] -- | uses System.FilePath.CurrentOS, but can automatically convert a Text (</>) :: (ToFilePath filepath) => filepath -> filepath -> FilePath@@ -182,13 +190,6 @@ (<.>) :: (ToFilePath filepath) => filepath -> Text -> FilePath x <.> y = toFilePath x FP.<.> LT.toStrict y --- | mappend a Text & FilePath. Warning: uses toTextIgnore-(<>|) :: Text -> FilePath -> Text-(<>|) t fp = t `mappend` toTextIgnore fp- --- | mappend a FilePath & Text. Warning: uses toTextIgnore-(|<>) :: FilePath -> Text -> Text-(|<>) fp t = toTextIgnore fp `mappend` t -- | silently uses the Right or Left value of "Filesystem.Path.CurrentOS.toText" toTextIgnore :: FilePath -> Text@@ -544,10 +545,6 @@ instance Exception RunFailed --- | An infix shorthand for "run". Write @\"command\" # [ \"argument\" ... ]@.-( # ) :: FilePath -> [Text] -> ShIO Text-exe # args = run exe args- -- | Execute an external command. Takes the command name (no shell allowed, -- just a name of something that can be found via @PATH@; FIXME: setenv'd -- @PATH@ is not taken into account, only the one inherited from the actual@@ -645,7 +642,7 @@ setStdin :: Text -> ShIO () setStdin input = modify $ \st -> st { sStdin = Just input } --- | set the output of the first command as the stdin of the second.+-- | Pipe operator. set the stdout the first command as the stdin of the second. (-|-) :: ShIO Text -> ShIO b -> ShIO b one -|- two = do res <- one
shelly.cabal view
@@ -1,6 +1,6 @@ Name: shelly -Version: 0.5.1+Version: 0.6 Synopsis: shell-like (systems) programming in Haskell Description: Shelly is a package provides a single module for convenient@@ -14,7 +14,7 @@ . * Shelly is modern. It uses Text and system-filepath/system-fileio .- These are all in contrast to HSH. Elegance in HSH comes from polymorphic input and output.+ * Shelly is aimed at convenience and newer Haskell users . Shelly is a fork of Shellish that features low memory usage, bug fixes, and modernization @@ -42,9 +42,12 @@ type: exitcode-stdio-1.0 main-is: main.hs hs-source-dirs: ., test+ ghc-options: -Wall - build-depends: base >= 4 && < 5- -- , hspec+ Build-depends: base >= 4 && < 5, time, directory, text, mtl, process+ , unix-compat < 0.4+ , system-filepath < 0.5+ , system-fileio < 0.4 -- demonstarated that command output in Shellish was not shown until after the command finished -- not necessary anymore
test/main.hs view
@@ -1,5 +1,10 @@ {-# Language OverloadedStrings #-}+{-# Language ExtendedDefaultRules #-}+{-# OPTIONS_GHC -fno-warn-type-defaults #-}+ import Shelly+import Data.Text.Lazy as LT+default (LT.Text) main :: IO () main =@@ -8,3 +13,6 @@ echo "echo" setStdin "catted" run_ "cat" ["-"]+ res <- cmd "echo" "foo"+ _<-cmd "echo" "bar" "baz"+ echo res