aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES1
-rw-r--r--driver/Main.hs28
2 files changed, 26 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 19639ef1..e170bc46 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,7 @@ Changes in version 2.16.1
* Don't print instance safety information in Hoogle (#168)
+ * Expand response files in arguments (#285)
Changes in version 2.16.0
diff --git a/driver/Main.hs b/driver/Main.hs
index 42b99860..5097a86d 100644
--- a/driver/Main.hs
+++ b/driver/Main.hs
@@ -1,7 +1,29 @@
+{-# LANGUAGE ScopedTypeVariables #-}
module Main where
-import Documentation.Haddock (haddock)
-import System.Environment (getArgs)
+import Control.Exception
+import Documentation.Haddock (haddock)
+import System.Environment (getArgs)
+import System.Exit (exitFailure)
+import System.IO
main :: IO ()
-main = getArgs >>= haddock
+main = getArgs >>= expandResponse >>= haddock
+
+
+-- | Arguments which look like '@foo' will be replaced with the
+-- contents of file @foo@. The contents will be passed through 'words'
+-- and blanks filtered out first.
+--
+-- We quit if the file is not found or reading somehow fails.
+expandResponse :: [String] -> IO [String]
+expandResponse = fmap concat . mapM expand
+ where
+ expand :: String -> IO [String]
+ expand ('@':f) = readFileExc f >>= return . filter (not . null) . words
+ expand x = return [x]
+
+ readFileExc f =
+ readFile f `catch` \(e :: IOException) -> do
+ hPutStrLn stderr $ "Error while expanding response file: " ++ show e
+ exitFailure