packages feed

executor 0.0.3 → 0.0.4

raw patch · 8 files changed

+98/−55 lines, 8 filesdep +doctestdep +executordep +hspecdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: doctest, executor, hspec

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Executor: exec :: String -> IO String
+ Executor: execSequenceSync :: [String] -> IO [String]
- Executor: execListSync :: [String] -> IO ()
+ Executor: execListSync :: [String] -> IO [String]
- Executor: execSync :: String -> IO ()
+ Executor: execSync :: String -> IO String

Files

ChangeLog.md view
@@ -1,5 +1,15 @@ # Revision history for executor +## 0.0.4  -- 2017-08-27++* Add better unit test+* Deprecate `execSync` and `execListSync` in favor of `exec` and `execSequenceSync`+* Return IO (String) to display the result of the commands triggered++## 0.0.3  -- 2017-08-20++* Reducing unecessary code+ ## 0.0.2  -- 2017-08-20  * Make the code a bit cleaner and consistent
− Executor.hs
@@ -1,25 +0,0 @@-module Executor (execSync, execListSync) where--import System.Process (callCommand)-import Control.Concurrent.Async (async, wait)---- | Execute a single shell command--- Not much different from callCommand though--- for example:--- main = do---  execSync "ls"--execSync :: String -> IO()--execSync c = do-  task <- async (callCommand c)-  wait task---- | Execute a list of shell commands in sequence synchronously--- for example:--- main = do---  execListSync ["ls", "whoami"]--execListSync :: [String] -> IO()--execListSync commands = do mapM_ execSync commands
README.md view
@@ -6,32 +6,34 @@  # API -## execSync+## exec -Execute a single shell command+Execute a single shell command returning its output  ```hs-import Executor (execSync)+import Executor (exec)  main = do   -- execute a simple `ls` in the current folder-  execSync "ls"+  res <- exec "echo hi"+  -- hi\n ``` -## execListSync+## execSequenceSync -Execute a list of shell commands in sequence synchronously+Execute a list of shell commands in sequence synchronously returning their results in a list  ```hs-import Executor (execListSync)+import Executor (execSequenceSync)  main = do   -- execute synchronously the following commands-  execListSync [-      "ls",-      "whoami",-      "echo hello"+  res <- execSequenceSync [+      "echo hi",+      "sleep 1",+      "echo goodbye"     ]+  -- ["hi\n", "", "goodbye\n"] ```  [travis-image]:https://img.shields.io/travis/GianlucaGuarini/executor.svg?style=flat-square
executor.cabal view
@@ -1,5 +1,5 @@ name:                executor-version:0.0.3+version:0.0.4 description:         Haskell module to execute single or multiple shell commands synopsis:            Shell helpers homepage:            https://github.com/GianlucaGuarini/executor@@ -17,15 +17,20 @@   type:              git   location:          https://github.com/GianlucaGuarini/executor -Test-Suite test-executor+Test-Suite spec   type:              exitcode-stdio-1.0-  main-is:           test.hs-  build-depends:     base >=4.9 && <4.10, process >=1.4 && <1.5, async >=2.1 && <2.2   default-language:  Haskell2010+  main-is:           test/Spec.hs+  build-depends:     executor, base >=4.9 && <4.10, process >=1.4 && <1.5, async >=2.1 && <2.2, hspec >= 2.2 +Test-Suite doctest+  type:              exitcode-stdio-1.0+  default-language:  Haskell2010+  main-is:           test/doctests.hs+  build-depends:     executor, base, doctest >= 0.8.0+ library   exposed-modules:   Executor-  build-depends:     base >=4.9 && <4.10, process >=1.4 && <1.5, async >=2.1 && <2.2-  hs-source-dirs:    ./   default-language:  Haskell2010-+  build-depends:     base >=4.9 && <4.10, process >=1.4 && <1.5, async >=2.1 && <2.2+  hs-source-dirs:    src
+ src/Executor.hs view
@@ -0,0 +1,44 @@+module Executor (execSync, exec, execSequenceSync, execListSync) where++import System.Process (readProcess)++-- | Simple split a string using a delimiter+-- for example:+-- split "foo bar" " " will return ["foo", "bar"]+split' :: String -> Char -> [String]+split' [] _ = [""]+split' (c:cs) delimiter+   | c == delimiter = "" : rest+   | otherwise = (c : head rest) : tail rest+   where+       rest = split' cs delimiter+++-- | Alias for exec+execSync :: String -> IO String+execSync = exec+-- | Alias for execSequenceSync+execListSync :: [String] -> IO [String]+execListSync = execSequenceSync++-- | Execute a single shell command returning its output+-- for example:+--+-- >>> execSync "echo hi"+-- "hi\n"+--+exec :: String -> IO String+exec c =  readProcess command arguments []+            where+              commandList = split' c ' '+              command = head commandList+              arguments = tail commandList++-- | Execute a list of shell commands in sequence synchronously+-- for example:+--+-- >>> execSequenceSync ["echo hi", "sleep 1", "echo goodbye"]+-- ["hi\n","","goodbye\n"]+--+execSequenceSync :: [String] -> IO [String]+execSequenceSync = mapM execSync
− test.hs
@@ -1,12 +0,0 @@-module Main where-import Executor-import System.Exit (exitSuccess)--main = do-  execSync "ls"-  execListSync [-      "echo hello",-      "sleep 1",-      "echo world"-    ]-  exitSuccess
+ test/Spec.hs view
@@ -0,0 +1,13 @@+module Main (main) where+import Executor+import Test.Hspec++main :: IO ()+main = hspec $ do+  describe "Executor.execSync" $+    it "It can execute a simple echo" $+      exec "echo hi" `shouldReturn` "hi\n"++  describe "Executor.execSequenceSync" $+    it "It can execute a command sequence" $+      execSequenceSync ["echo hi", "sleep 1", "echo goodbye"] `shouldReturn` ["hi\n", "", "goodbye\n"]
+ test/doctests.hs view
@@ -0,0 +1,6 @@+module Main where++import Test.DocTest++main :: IO ()+main = doctest ["src/Executor.hs"]