simple-cmd 0.1.0.0 → 0.1.1
raw patch · 6 files changed
+81/−18 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ SimpleCmd: cmdLines :: String -> [String] -> IO [String]
+ SimpleCmd.Git: grepGitConfig :: String -> IO Bool
+ SimpleCmd.Rpm: rpmspec :: [String] -> Maybe String -> FilePath -> IO [String]
Files
- ChangeLog.md +5/−0
- README.md +30/−2
- SimpleCmd.hs +10/−0
- SimpleCmd/Git.hs +14/−8
- SimpleCmd/Rpm.hs +12/−0
- simple-cmd.cabal +10/−8
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for simple-cmd +## 0.1.1 -- 2018-10-02+- cmdLines+- Git: grepGitConfig+- new Rpm: rpmspec+ ## 0.1.0.0 -- 2018-09-13 - Initial release, providing:
README.md view
@@ -1,11 +1,39 @@ [](https://travis-ci.org/juhp/simple-cmd)+[](http://hackage.haskell.org/package/simple-cmd) # simple-cmd Some simple String wrappers of `readProcess`, `readProcessWithExitCode`, `rawSystem` from the Haskell `process` library. -It can also be used as a copy library.+## Usage -## Examples+```haskell+import SimpleCmd+``` +```haskell+cmd_ :: String -> [String] -> IO ()+```+outputs to stdout. For example++```haskell+cmd_ "git" ["clone", url]+```+This can shortened to `git_ "clone" [url]`.++```haskell+cmd :: String -> [String] -> IO String+```+returns stdout as a `String`.++There are also `cmdBool`, `cmdMaybe`, `cmdList`, `shell`, and others.++Other examples:+```haskell+gitBranch :: IO String+grep_ pat file :: IO Bool+sudo c args :: IO ()+```++See the library documentation for more details.
SimpleCmd.hs view
@@ -2,6 +2,7 @@ cmd, cmd_, cmdBool, cmdIgnoreErr,+ cmdLines, cmdlog, cmdMaybe, cmdN,@@ -65,6 +66,11 @@ ExitSuccess -> return $ Just $ removeTrailingNewline out ExitFailure _ -> return Nothing +-- | Run command, return list of stdout lines+-- | since 0.1.1+cmdLines :: String -> [String] -> IO [String]+cmdLines c args = lines <$> cmd c args+ -- | Run a command, passing input string as stdin, and return stdout cmdStdIn :: String -> [String] -> String -> IO String cmdStdIn c args inp = removeTrailingNewline <$> readProcess c args inp@@ -127,6 +133,10 @@ cmdIgnoreErr c args input = do (_exit, out, _err) <- readProcessWithExitCode c args input return out++-- grep :: String -> FilePath -> IO [String]+-- grep pat file =+-- cmdLines "grep" [pat, file] -- | grep a pattern in file and return Boolean status grep_ :: String -> FilePath -> IO Bool
SimpleCmd/Git.hs view
@@ -2,14 +2,15 @@ git, git_, gitBranch,+ grepGitConfig, isGitDir, rwGitDir) where import Data.List (isPrefixOf)-import System.Directory (doesDirectoryExist, getCurrentDirectory)+import System.Directory (doesDirectoryExist) import System.FilePath ((</>)) -import SimpleCmd (cmd, cmd_, egrep_, removePrefix)+import SimpleCmd (cmd, cmd_, cmdLines, egrep_, removePrefix) #if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,8,2)) #else@@ -33,13 +34,18 @@ -- | Return the git branch of the current directory gitBranch :: IO String gitBranch =- removePrefix "* " . head . filter (isPrefixOf "* ") . lines <$> cmd "git" ["branch"]+ removePrefix "* " . head . filter (isPrefixOf "* ") <$> cmdLines "git" ["branch"] -- | Check if a git repo is under ssh rwGitDir :: IO Bool-rwGitDir = do- gitDir <- getCurrentDirectory >>= isGitDir- if gitDir- then egrep_ "url = (ssh://|git@)" ".git/config"- else return False+rwGitDir =+ grepGitConfig "url = (ssh://|git@)" +-- | grep ".git/config"+-- | since 0.1.1+grepGitConfig :: String -> IO Bool+grepGitConfig key = do+ gitdir <- isGitDir "."+ if gitdir+ then egrep_ key ".git/config"+ else return False
+ SimpleCmd/Rpm.hs view
@@ -0,0 +1,12 @@+module SimpleCmd.Rpm (+ rpmspec+ ) where++import SimpleCmd (cmdLines)++-- | Run rpmspec query on file with optional args, a newline is appended to any queryformat+-- | since 0.1.1+rpmspec :: [String] -> Maybe String -> FilePath -> IO [String]+rpmspec args mqf spec = do+ let qf = maybe [] (\ q -> ["--queryformat", q ++ "\n"]) mqf+ cmdLines "rpmspec" (["-q"] ++ args ++ qf ++ [spec])
simple-cmd.cabal view
@@ -1,12 +1,12 @@ name: simple-cmd-version: 0.1.0.0+version: 0.1.1 synopsis: Simple String-based process commands description:- Thin wrappers over the System.Process (readProcess,- readProcessWithExitCode, and rawSystem). The idea is just- to provide some simple common idioms for easy calling out- to commands from programs. For proper shell-scripting- please use turtle, shelly, command, etc.+ Thin wrappers over System.Process (readProcess,+ readProcessWithExitCode, and rawSystem). The idea is to provide+ some simple common idioms for easy calling out to commands+ from programs. For more advanced shell-scripting or streaming+ use turtle, shelly, command, etc. license: BSD3 license-file: LICENSE author: Jens Petersen@@ -17,7 +17,8 @@ cabal-version: >=1.10 extra-source-files: README.md ChangeLog.md TODO tested-with: GHC == 7.0.4, GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4,- GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.3+ GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.3,+ GHC == 8.6.1 source-repository head type: git@@ -25,7 +26,8 @@ library exposed-modules: SimpleCmd,- SimpleCmd.Git+ SimpleCmd.Git,+ SimpleCmd.Rpm build-depends: base < 5, directory, filepath, process default-language: Haskell2010 default-extensions: CPP