aboutsummaryrefslogtreecommitdiff
path: root/driver/Main.hs
blob: 5097a86dfcd94f9bc89efdbf39cd604e0e664431 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# LANGUAGE ScopedTypeVariables #-}
module Main where

import Control.Exception
import Documentation.Haddock (haddock)
import System.Environment (getArgs)
import System.Exit (exitFailure)
import System.IO

main :: IO ()
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