aboutsummaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>2015-03-28 20:38:10 +0000
committerMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>2015-03-28 20:39:10 +0000
commitd567a12b2d24bab610cd7e8f8014d40c7615e24d (patch)
tree312b91f6d7c43aa45d5e7c5ba07ad35ca8eaded1 /driver
parent8ba7777c5db203512263934dfe40d56c1b4199b8 (diff)
Expand response files in arguments
Closes #285
Diffstat (limited to 'driver')
-rw-r--r--driver/Main.hs28
1 files changed, 25 insertions, 3 deletions
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