on e8a41dc help sign in
Idris-dev/main/Main.hs
109 lines 3.2 kB history raw
1module Main where
3import System.Console.Haskeline
4import System.IO
5import System.Environment
6import System.Exit
7import System.FilePath ((</>), addTrailingPathSeparator)
8import System.Directory
10import Data.Maybe
11import Data.Version
12import Control.Monad.Trans.State.Strict ( execStateT, get, put )
13import Control.Monad ( when )
15import Idris.Core.TT
16import Idris.Core.Typecheck
17import Idris.Core.Evaluate
18import Idris.Core.Constraints
20import Idris.AbsSyntax
21import Idris.Parser
22import Idris.REPL
23import Idris.ElabDecls
24import Idris.Primitives
25import Idris.Imports
26import Idris.Error
27import Idris.CmdOptions
29import IRTS.System ( getLibFlags, getIdrisLibDir, getIncFlags )
31import Util.DynamicLinker
32import Util.System
34import Pkg.Package
36import Paths_idris
38-- Main program reads command line options, parses the main program, and gets
39-- on with the REPL.
41main :: IO ()
42main = do opts <- runArgParser
43 runMain (runIdris opts)
45runIdris :: [Opt] -> Idris ()
46runIdris opts = do
47 runIO setupBundledCC
48 when (ShowLoggingCats `elem` opts) $ runIO showLoggingCats
49 when (ShowIncs `elem` opts) $ runIO showIncs
50 when (ShowLibs `elem` opts) $ runIO showLibs
51 when (ShowLibdir `elem` opts) $ runIO showLibdir
52 when (ShowPkgs `elem` opts) $ runIO showPkgs
53 case opt getClient opts of
54 [] -> return ()
55 (c:_) -> do setVerbose False
56 setQuiet True
57 runIO $ runClient (getPort opts) c
58 runIO $ exitWith ExitSuccess
59 case opt getPkgCheck opts of
60 [] -> return ()
61 fs -> do runIO $ mapM_ (checkPkg (WarnOnly `elem` opts) True) fs
62 runIO $ exitWith ExitSuccess
63 case opt getPkgClean opts of
64 [] -> return ()
65 fs -> do runIO $ mapM_ cleanPkg fs
66 runIO $ exitWith ExitSuccess
67 case opt getPkgMkDoc opts of -- IdrisDoc
68 [] -> return ()
69 fs -> do runIO $ mapM_ documentPkg fs
70 runIO $ exitWith ExitSuccess
71 case opt getPkgTest opts of
72 [] -> return ()
73 fs -> do runIO $ mapM_ testPkg fs
74 runIO $ exitWith ExitSuccess
75 case opt getPkg opts of
76 [] -> case opt getPkgREPL opts of
77 [] -> idrisMain opts
78 [f] -> replPkg f
79 _ -> ifail "Too many packages"
80 fs -> runIO $ mapM_ (buildPkg (WarnOnly `elem` opts)) fs
82showver :: IO b
83showver = do putStrLn $ "Idris version " ++ ver
84 exitWith ExitSuccess
86showLibs :: IO b
87showLibs = do libFlags <- getLibFlags
88 putStrLn $ unwords libFlags
89 exitWith ExitSuccess
91showLibdir :: IO b
92showLibdir = do dir <- getIdrisLibDir
93 putStrLn dir
94 exitWith ExitSuccess
96showIncs :: IO b
97showIncs = do incFlags <- getIncFlags
98 putStrLn $ unwords incFlags
99 exitWith ExitSuccess
101-- | List idris packages installed
102showPkgs :: IO b
103showPkgs = do mapM putStrLn =<< installedPackages
104 exitWith ExitSuccess
106showLoggingCats :: IO b
107showLoggingCats = do
108 putStrLn loggingCatsStr
109 exitWith ExitSuccess