mirror of
https://github.com/kowainik/shellmet.git
synced 2024-10-26 11:28:21 +03:00
parent
f4742e2f27
commit
39674a6075
@ -4,7 +4,7 @@ language: haskell
|
|||||||
git:
|
git:
|
||||||
depth: 5
|
depth: 5
|
||||||
|
|
||||||
cabal: "2.0"
|
cabal: "2.4"
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
@ -18,12 +18,6 @@ matrix:
|
|||||||
- ghc: 8.4.4
|
- ghc: 8.4.4
|
||||||
- ghc: 8.6.3
|
- ghc: 8.6.3
|
||||||
|
|
||||||
- ghc: 8.2.2
|
|
||||||
env: STACK_YAML="$TRAVIS_BUILD_DIR/stack-8.2.2.yaml"
|
|
||||||
|
|
||||||
- ghc: 8.4.4
|
|
||||||
env: STACK_YAML="$TRAVIS_BUILD_DIR/stack-8.4.4.yaml"
|
|
||||||
|
|
||||||
- ghc: 8.6.3
|
- ghc: 8.6.3
|
||||||
env: STACK_YAML="$TRAVIS_BUILD_DIR/stack.yaml"
|
env: STACK_YAML="$TRAVIS_BUILD_DIR/stack.yaml"
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ cabal-version: 2.0
|
|||||||
name: shellmet
|
name: shellmet
|
||||||
version: 0.0.0
|
version: 0.0.0
|
||||||
synopsis: Out of the shell solution for scripting in Haskell
|
synopsis: Out of the shell solution for scripting in Haskell
|
||||||
description: Out of the shell solution for scripting in Haskell
|
description: Shellmet provides easy and convenient way to call shell commands from Haskell programs
|
||||||
homepage: https://github.com/kowainik/shellmet
|
homepage: https://github.com/kowainik/shellmet
|
||||||
bug-reports: https://github.com/kowainik/shellmet/issues
|
bug-reports: https://github.com/kowainik/shellmet/issues
|
||||||
license: MPL-2.0
|
license: MPL-2.0
|
||||||
@ -14,7 +14,9 @@ category: Shell, Command Line
|
|||||||
build-type: Simple
|
build-type: Simple
|
||||||
extra-doc-files: README.md
|
extra-doc-files: README.md
|
||||||
, CHANGELOG.md
|
, CHANGELOG.md
|
||||||
tested-with: GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.3
|
tested-with: GHC == 8.2.2
|
||||||
|
GHC == 8.4.4
|
||||||
|
GHC == 8.6.3
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
@ -24,9 +26,9 @@ library
|
|||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
exposed-modules: Shellmet
|
exposed-modules: Shellmet
|
||||||
|
|
||||||
|
|
||||||
build-depends: base >= 4.10.1.0 && < 4.13
|
build-depends: base >= 4.10.1.0 && < 4.13
|
||||||
|
, process ^>= 1.6.3
|
||||||
|
, text ^>= 1.2.3
|
||||||
|
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
-Wincomplete-uni-patterns
|
-Wincomplete-uni-patterns
|
||||||
|
@ -1,6 +1,66 @@
|
|||||||
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||||
|
|
||||||
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
|
|
||||||
|
{- | This module contains neat utilities to be able to work with
|
||||||
|
shell commands in generic and simple way using just strings.
|
||||||
|
-}
|
||||||
|
|
||||||
module Shellmet
|
module Shellmet
|
||||||
( someFunc
|
( ($|)
|
||||||
|
, ($?)
|
||||||
) where
|
) where
|
||||||
|
|
||||||
someFunc :: IO ()
|
import Control.Exception (catch)
|
||||||
someFunc = putStrLn ("someFunc" :: String)
|
import Data.String (IsString (..))
|
||||||
|
import Data.Text (Text)
|
||||||
|
import System.Process (callCommand, readProcess, showCommandForUser)
|
||||||
|
|
||||||
|
import qualified Data.Text as T
|
||||||
|
|
||||||
|
|
||||||
|
{- | This instance is needed to provide functionality to call commands by using
|
||||||
|
simple string literals in 'IO' monad.
|
||||||
|
|
||||||
|
>>> "ls" ["-1"]
|
||||||
|
⚙ ls -1
|
||||||
|
CHANGELOG.md
|
||||||
|
CONTRIBUTING.md
|
||||||
|
dist-newstyle
|
||||||
|
LICENSE
|
||||||
|
README.md
|
||||||
|
shellmet.cabal
|
||||||
|
src
|
||||||
|
stack.yaml
|
||||||
|
test
|
||||||
|
-}
|
||||||
|
instance (a ~ [Text], b ~ IO ()) => IsString (a -> b) where
|
||||||
|
fromString :: String -> [Text] -> IO ()
|
||||||
|
fromString cmd args = do
|
||||||
|
let cmdStr = showCommandForUser cmd (map T.unpack args)
|
||||||
|
putStrLn $ "⚙ " ++ cmdStr
|
||||||
|
callCommand cmdStr
|
||||||
|
|
||||||
|
{- | Run shell command with given options and return stripped stdout of the
|
||||||
|
executed command.
|
||||||
|
|
||||||
|
>>> "echo" $| ["Foo", "Bar"]
|
||||||
|
"Foo Bar"
|
||||||
|
-}
|
||||||
|
infix 5 $|
|
||||||
|
($|) :: FilePath -> [Text] -> IO Text
|
||||||
|
cmd $| args = T.strip . T.pack <$> readProcess cmd (map T.unpack args) ""
|
||||||
|
|
||||||
|
{- | Do some IO actions when processed failed with error.
|
||||||
|
|
||||||
|
>>> "exit" ["0"] $? putStrLn "Command failed"
|
||||||
|
⚙ exit 0
|
||||||
|
|
||||||
|
>>> "exit" ["1"] $? putStrLn "Command failed"
|
||||||
|
⚙ exit 1
|
||||||
|
Command failed
|
||||||
|
-}
|
||||||
|
infixl 4 $?
|
||||||
|
($?) :: IO () -> IO () -> IO ()
|
||||||
|
action $? handler = action `catch` \(_ :: IOError) -> handler
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
resolver: lts-11.22
|
|
||||||
|
|
||||||
ghc-options:
|
|
||||||
"$locals": -fhide-source-paths
|
|
@ -1,4 +0,0 @@
|
|||||||
resolver: lts-12.25
|
|
||||||
|
|
||||||
ghc-options:
|
|
||||||
"$locals": -fhide-source-paths
|
|
Loading…
Reference in New Issue
Block a user