module NLP.GenI.MainGui where
import Data.IORef (newIORef)
import Data.Typeable (Typeable)
import Data.Version (showVersion)
import System.Environment (getArgs, getProgName)
import NLP.GenI (ProgState (..), defaultCustomSem,
emptyProgState)
import NLP.GenI.Configuration (optionsForStandardGenI,
optionsSections,
processInstructions,
readGlobalConfig, setLoggers,
treatArgs, usage)
import NLP.GenI.Console (consoleGeni)
import NLP.GenI.Flag
import NLP.GenI.Gui (guiGeni)
import NLP.GenI.LexicalSelection
import Paths_geni_gui (version)
main :: IO ()
main = do
stuff <- processInstructions
=<< treatArgs optionsForStandardGenI
=<< getArgs
let pst = emptyProgState stuff
wrangler <- defaultCustomSem pst
mainWithState pst wrangler
mainWithState :: ProgState -> CustomSem sem -> IO ()
mainWithState pst wrangler = do
pname <- getProgName
maybe (return ()) setLoggers =<< readGlobalConfig
pstRef <- newIORef pst
let has :: (Typeable f, Typeable x) => (x -> f) -> Bool
has = flip hasFlag pst
mustRunInConsole = has DumpDerivationFlg || has FromStdinFlg
|| has BatchDirFlg
case () of
_ | has HelpFlg -> putStrLn (usage optionsSections pname)
| has VersionFlg -> putStrLn ("GenI " ++ showVersion version)
| mustRunInConsole -> consoleGeni pstRef wrangler
| otherwise -> guiGeni pstRef wrangler