Browse files

Use showCommandForUser when it's available (GHC >= 7.2)

  • Loading branch information...
1 parent c34262a commit 42eddffc6009ade6e8c73061c70cbec7d268e853 @igfoo igfoo committed Nov 8, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 Cabal/Distribution/Simple/Utils.hs
View
10 Cabal/Distribution/Simple/Utils.hs
@@ -199,6 +199,9 @@ import System.Process (runProcess)
#ifdef __GLASGOW_HASKELL__
import Control.Concurrent (forkIO)
import System.Process (runInteractiveProcess, waitForProcess)
+#if __GLASGOW_HASKELL__ >= 602
+import System.Process (showCommandForUser)
+#endif
#else
import System.Cmd (system)
import System.Directory (getTemporaryDirectory)
@@ -359,7 +362,12 @@ maybeExit cmd = do
printRawCommandAndArgs :: Verbosity -> FilePath -> [String] -> IO ()
printRawCommandAndArgs verbosity path args
| verbosity >= deafening = print (path, args)
- | verbosity >= verbose = putStrLn $ unwords (path : args)
+ | verbosity >= verbose =
+#if __GLASGOW_HASKELL__ >= 602
+ putStrLn $ showCommandForUser path args
+#else
+ putStrLn $ unwords (path : args)
+#endif
| otherwise = return ()
printRawCommandAndArgsAndEnv :: Verbosity

1 comment on commit 42eddff

@tibbe
Haskell member

We should probably try to improve showCommandForUser a bit, as it now naively quotes everything, making commands a bit hard to read. Something like this:

showRawCommandAndArgs :: FilePath -> [String] -> String
showRawCommandAndArgs path args = unwords (map shellEscape (path : args))

shellEscape :: String -> String
shellEscape str
    | '\'' `elem` str || ' ' `elem` str = '\'' : foldr escape "'" str
    | otherwise = str
  where escape '\'' = showString "'\\''"
        escape c    = showChar c
Please sign in to comment.