packages feed

handsy 0.0.3 → 0.0.4

raw patch · 3 files changed

+36/−16 lines, 3 files

Files

handsy.cabal view
@@ -1,5 +1,5 @@ name:          handsy-version:       0.0.3+version:       0.0.4 synopsis:      A DSL to describe common shell operations and interpeters for running them locally and remotely. -- description:    Homepage:      https://github.com/utdemir/handsy
src/System/Handsy.hs view
@@ -1,7 +1,4 @@-{-# LANGUAGE DeriveFunctor     #-}-{-# LANGUAGE FlexibleContexts  #-} {-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE TemplateHaskell   #-}  module System.Handsy where @@ -13,22 +10,42 @@ import           Control.Monad.Trans.Free import           System.Process.ByteString.Lazy --- * Types-data HandsyF k =-    Command      FilePath [String] B.ByteString ((ExitCode, B.ByteString, B.ByteString) -> k)-  | ReadFile     FilePath                       (B.ByteString -> k)-  | WriteFile    FilePath B.ByteString          (() -> k)-  | AppendFile   FilePath B.ByteString          (() -> k)-  deriving (Functor)+import           System.Handsy.Internal         (HandsyF (..))+import qualified System.Handsy.Internal         as T -type Handsy = FreeT HandsyF IO+type Handsy = FreeT T.HandsyF IO --- * TH generated actions-makeFree ''HandsyF+-- * Actions +-- | Runs a command+command :: FilePath     -- ^ Command to run+        -> [String]     -- ^ Arguments+        -> B.ByteString -- ^ Standart Input+        -> Handsy (ExitCode, B.ByteString, B.ByteString) -- ^ (status, stdout, stderr)+command = T.command++-- | Reads a file and returns the contents of the file.+readFile :: FilePath -> Handsy B.ByteString+readFile = T.readFile++-- | 'writeFile' @file str@ function writes the bytestring @str@, to the file @file@.+writeFile :: FilePath -> B.ByteString -> Handsy ()+writeFile = T.writeFile++-- | 'appendFile' @file str@ function appends the bytestring @str@, to the file @file@.+appendFile :: FilePath -> B.ByteString -> Handsy ()+appendFile = T.appendFile+ -- * Helpers-shell :: String -> Handsy (ExitCode, B.ByteString, B.ByteString)-shell cmd = command "/usr/bin/env" ["sh", "-c", cmd] ""++{-| Executes the given string in shell++  > shell cmd stdin = command "/usr/bin/env" ["sh", "-c", cmd] stdin+-}+shell :: String       -- ^ String to execute+      -> B.ByteString -- ^ Standart input+      -> Handsy (ExitCode, B.ByteString, B.ByteString) -- ^ (ExitCode, Stdout, Stderr)+shell cmd stdin = command "/usr/bin/env" ["sh", "-c", cmd] stdin  -- * Interpreter 
src/System/Handsy/Remote.hs view
@@ -2,6 +2,7 @@ module System.Handsy.Remote where  import           System.Handsy            as H+import           System.Handsy.Internal   (HandsyF (..))  import qualified Data.ByteString.Lazy     as B @@ -32,11 +33,13 @@     (ssh, sshOpts) = sshCommand opts     runSsh prg args stdin = run (command ssh (sshOpts ++ prg : args) stdin) +-- | Copies a local file to remote host pushFile :: FilePath -- ^ Local path of source          -> FilePath -- ^ Remote path of destination          -> Handsy () pushFile local remote = liftIO (B.readFile local) >>= H.writeFile remote +-- | Fetches a file from remote host pullFile :: FilePath -- ^ Remote path of source          -> FilePath -- ^ Local path of destination          -> Handsy ()