Skip to content

Commit

Permalink
Add --output command line argument
Browse files Browse the repository at this point in the history
If specified, write to the named file, otherwise write tags to stdout
as per the current default behaviour.
  • Loading branch information
istathar committed May 5, 2014
1 parent bbad6e1 commit 93ccbf8
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Main.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Main where


import qualified Language.Haskell.Exts.Annotated as L import qualified Language.Haskell.Exts.Annotated as L
import System.Console.CmdArgs import System.Console.CmdArgs
import System.IO (hPutStrLn, stderr) import System.IO (hPutStrLn, stderr, stdout, IOMode(..), openFile, hClose)
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Language.Preprocessor.Cpphs as CPP import qualified Language.Preprocessor.Cpphs as CPP
import Control.Monad (forM) import Control.Monad (forM)
Expand Down Expand Up @@ -233,7 +233,7 @@ moduleFile (L.Module (L.SrcSpanInfo (L.SrcSpan file _ _ _ _) _) _ _ _ _) = file
moduleFile _ = error "Wtf is an XmlPage/XmlHybrid?" moduleFile _ = error "Wtf is an XmlPage/XmlHybrid?"


data HotHasktags = HotHasktags { data HotHasktags = HotHasktags {
hh_files, hh_language, hh_define, hh_include, hh_cpphs :: [String] } hh_files, hh_language, hh_define, hh_include, hh_output, hh_cpphs :: [String] }
deriving (Data,Typeable,Show) deriving (Data,Typeable,Show)


defaultHotHasktags :: HotHasktags defaultHotHasktags :: HotHasktags
Expand All @@ -257,6 +257,11 @@ defaultHotHasktags = HotHasktags {
\paths are currently interpreted as relative to the directory \ \paths are currently interpreted as relative to the directory \
\containing the source file \ \containing the source file \
\-Ifoo is a shortcut for -c -Ifoo", \-Ifoo is a shortcut for -c -Ifoo",
hh_output = []
&= name "output" &= name "O"
&= explicit
&= typ "FILE"
&= help "Name of output file. Default is to write to stdout",
hh_cpphs = [] hh_cpphs = []
&= name "cpp" &= name "c" &= name "cpp" &= name "c"
&= explicit &= explicit
Expand All @@ -275,4 +280,12 @@ main = do
++ unknown ++ unknown
database <- makeDatabase exts conf database <- makeDatabase exts conf
let tags = sort $ concatMap (\mod -> makeTags (moduleFile mod) (moduleScope database mod)) (Map.elems database) let tags = sort $ concatMap (\mod -> makeTags (moduleFile mod) (moduleScope database mod)) (Map.elems database)
mapM_ putStrLn tags handle <- case (hh_output conf) of
[] -> return stdout
file:_ -> openFile file WriteMode

mapM_ (hPutStrLn handle) tags

case (hh_output conf) of
[] -> return ()
_ -> hClose handle

0 comments on commit 93ccbf8

Please sign in to comment.