aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver/Main.hs7
-rw-r--r--haddock.cabal6
-rw-r--r--src/Documentation/Haddock.hs7
-rw-r--r--src/Haddock.hs (renamed from src/Main.hs)15
4 files changed, 24 insertions, 11 deletions
diff --git a/driver/Main.hs b/driver/Main.hs
new file mode 100644
index 00000000..42b99860
--- /dev/null
+++ b/driver/Main.hs
@@ -0,0 +1,7 @@
+module Main where
+
+import Documentation.Haddock (haddock)
+import System.Environment (getArgs)
+
+main :: IO ()
+main = getArgs >>= haddock
diff --git a/haddock.cabal b/haddock.cabal
index 91c2e494..42dc9771 100644
--- a/haddock.cabal
+++ b/haddock.cabal
@@ -95,10 +95,12 @@ executable haddock
build-depends: ghc-paths
main-is: Main.hs
- hs-source-dirs: src
+ hs-source-dirs: src, driver
ghc-options: -funbox-strict-fields -O2 -Wall -fwarn-tabs
other-modules:
+ Documentation.Haddock
+ Haddock
Haddock.Interface
Haddock.Interface.Rename
Haddock.Interface.Create
@@ -157,7 +159,7 @@ library
Documentation.Haddock
other-modules:
- Main
+ Haddock
Haddock.Interface
Haddock.Interface.Rename
Haddock.Interface.Create
diff --git a/src/Documentation/Haddock.hs b/src/Documentation/Haddock.hs
index cbdc4d61..855cdc79 100644
--- a/src/Documentation/Haddock.hs
+++ b/src/Documentation/Haddock.hs
@@ -48,8 +48,10 @@ module Documentation.Haddock (
-- * Flags and options
Flag(..),
- DocOption(..)
+ DocOption(..),
+ -- * Program entry point
+ haddock,
) where
@@ -58,7 +60,7 @@ import Haddock.Interface
import Haddock.Types
import Haddock.Options
import Haddock.Utils
-import Main
+import Haddock
-- | Create 'Interface' structures from a given list of Haddock command-line
@@ -72,4 +74,3 @@ createInterfaces
createInterfaces flags modules = do
(_, ifaces, _) <- withGhc' flags (readPackagesAndProcessModules flags modules)
return ifaces
-
diff --git a/src/Main.hs b/src/Haddock.hs
index abeda77f..f53e01a9 100644
--- a/src/Main.hs
+++ b/src/Haddock.hs
@@ -2,7 +2,7 @@
{-# LANGUAGE CPP, ScopedTypeVariables #-}
-----------------------------------------------------------------------------
-- |
--- Module : Main
+-- Module : Haddock
-- Copyright : (c) Simon Marlow 2003-2006,
-- David Waern 2006-2010
-- License : BSD-like
@@ -15,7 +15,7 @@
--
-- Program entry point and top-level code.
-----------------------------------------------------------------------------
-module Main (main, readPackagesAndProcessModules, withGhc') where
+module Haddock (haddock, readPackagesAndProcessModules, withGhc') where
import Haddock.Backends.Xhtml
@@ -39,7 +39,6 @@ import Data.IORef
import qualified Data.Map as Map
import System.IO
import System.Exit
-import System.Environment
#if defined(mingw32_HOST_OS)
import Foreign
@@ -123,14 +122,18 @@ handleGhcExceptions =
-------------------------------------------------------------------------------
-main :: IO ()
-main = handleTopExceptions $ do
+-- | Run Haddock with given list of arguments.
+--
+-- Haddock's own main function is defined in terms of this:
+--
+-- > main = getArgs >>= haddock
+haddock :: [String] -> IO ()
+haddock args = handleTopExceptions $ do
-- Parse command-line flags and handle some of them initially.
-- TODO: unify all of this (and some of what's in the 'render' function),
-- into one function that returns a record with a field for each option,
-- or which exits with an error or help message.
- args <- getArgs
(flags, files) <- parseHaddockOpts args
shortcutFlags flags
qual <- case qualification flags of {Left msg -> throwE msg; Right q -> return q}