module NLP.GenI.Main where
import Control.Applicative ((<$>))
import Data.IORef (newIORef)
import Data.Typeable (Typeable)
import Data.Version (showVersion)
import System.Environment (getArgs, getProgName)
import Paths_GenI (version)
import NLP.GenI (ProgState (..), defaultCustomSem,
emptyProgState)
import NLP.GenI.Flag
import NLP.GenI.Configuration (Params,
optionsForStandardGenI,
optionsSections,
processInstructions,
readGlobalConfig,
setLoggers, treatArgs, usage)
import NLP.GenI.Console (consoleGeni)
import NLP.GenI.LexicalSelection (CustomSem (..))
main :: IO ()
main = do
args <- getArgs
confArgs <- forceGuiFlag <$> (processInstructions =<< treatArgs optionsForStandardGenI args)
let pst = emptyProgState confArgs
wrangler <- defaultCustomSem pst
mainWithState pst wrangler
mainWithState :: ProgState -> CustomSem sem -> IO ()
mainWithState pst wrangler = do
maybe (return ()) setLoggers =<< readGlobalConfig
pname <- getProgName
let has :: (Typeable f, Typeable x) => (x -> f) -> Bool
has = flip hasFlag pst
pstRef <- newIORef pst
case () of
_ | has HelpFlg -> putStrLn (usage optionsSections pname)
| has VersionFlg -> putStrLn (pname ++ " " ++ showVersion version)
| otherwise -> consoleGeni pstRef wrangler
forceGuiFlag :: Params -> Params
forceGuiFlag = setFlag DisableGuiFlg ()