Skip to content

Commit

Permalink
do not use unix and provide sudo commands for Windows (juhp/stack-cle…
Browse files Browse the repository at this point in the history
  • Loading branch information
juhp committed Jun 4, 2022
1 parent 94671b7 commit 2f9e7c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions simple-cmd.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: simple-cmd
version: 0.2.6
version: 0.2.7
synopsis: Simple String-based process commands
description:
Simple wrappers over System.Process
Expand All @@ -20,6 +20,7 @@ cabal-version: >=1.10
extra-source-files: README.md ChangeLog.md TODO
tested-with: GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4,
GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2
GHC == 9.2.2

source-repository head
type: git
Expand All @@ -35,8 +36,9 @@ library
extra,
filepath,
process >= 1.4.3.0,
time,
unix
time
if !os(windows)
build-depends: unix
default-language: Haskell2010
default-extensions: CPP
ghc-options: -Wall
Expand Down
6 changes: 6 additions & 0 deletions src/SimpleCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ module SimpleCmd (
egrep_, grep, grep_,
shell, shell_,
shellBool,
#ifndef mingw32_HOST_OS
sudo, sudo_,
#endif
PipeCommand,
pipe, pipe_, pipeBool,
pipe3, pipe3_, pipeFile_,
Expand Down Expand Up @@ -85,7 +87,9 @@ import System.Exit (ExitCode (..))
import System.FilePath
import System.IO (hGetContents, hPutStr, hPutStrLn, IOMode(ReadMode),
stderr, stdout, withFile, Handle)
#ifndef mingw32_HOST_OS
import System.Posix.User (getEffectiveUserID)
#endif
import System.Process (createProcess, CreateProcess (cmdspec), proc,
ProcessHandle,
rawSystem, readProcess,
Expand Down Expand Up @@ -298,6 +302,7 @@ egrep_ :: String -> FilePath -> IO Bool
egrep_ pat file =
cmdBool "grep" ["-q", "-e", pat, file]

#ifndef mingw32_HOST_OS
-- | @sudo c args@ runs a command as sudo returning stdout
--
-- Result type changed from IO () to IO String in 0.2.0
Expand All @@ -324,6 +329,7 @@ sudoInternal exc c args = do
when (uid /= 0 && noSudo) $
warning "'sudo' not found"
exc (fromMaybe c sd) (if noSudo then args else c:args)
#endif

-- | Combine two strings with a single space
infixr 4 +-+
Expand Down

0 comments on commit 2f9e7c8

Please sign in to comment.