on bbefa33 help sign in
Idris-dev/main/Main.hs
81 lines 2.9 kB history raw
1module Main where
3import System.Exit (ExitCode(..), exitSuccess, exitWith)
5import Control.Monad (unless, when)
7import Idris.AbsSyntax
8import Idris.CmdOptions
9import Idris.Error
10import Idris.Info.Show
11import Idris.Main
12import Idris.Options
13import Idris.Package
15import Util.System (setupBundledCC)
17processShowOptions :: [Opt] -> Idris ()
18processShowOptions opts = runIO $ do
19 when (ShowAll `elem` opts) $ showExitIdrisInfo
20 when (ShowLoggingCats `elem` opts) $ showExitIdrisLoggingCategories
21 when (ShowIncs `elem` opts) $ showExitIdrisFlagsInc
22 when (ShowLibs `elem` opts) $ showExitIdrisFlagsLibs
23 when (ShowLibDir `elem` opts) $ showExitIdrisLibDir
24 when (ShowDocDir `elem` opts) $ showExitIdrisDocDir
25 when (ShowPkgs `elem` opts) $ showExitIdrisInstalledPackages
27check :: [Opt] -> (Opt -> Maybe a) -> ([a] -> Idris ()) -> Idris ()
28check opts extractOpts action = do
29 case opt extractOpts opts of
30 [] -> return ()
31 fs -> do action fs
32 runIO exitSuccess
34processClientOptions :: [Opt] -> Idris ()
35processClientOptions opts = check opts getClient $ \fs -> case fs of
36 [] -> ifail "No --client argument. This indicates a bug. Please report."
37 (c : _) -> do
38 setVerbose 0
39 setQuiet True
40 case getPort opts of
41 Just DontListen -> ifail "\"--client\" and \"--port none\" are incompatible"
42 Just (ListenPort port) -> runIO $ runClient (Just port) c
43 Nothing -> runIO $ runClient Nothing c
45processPackageOptions :: [Opt] -> Idris ()
46processPackageOptions opts = do
47 check opts getPkgCheck $ \fs -> runIO $ do
48 mapM_ (checkPkg opts (WarnOnly `elem` opts) True) fs
49 check opts getPkgClean $ \fs -> runIO $ do
50 mapM_ (cleanPkg opts) fs
51 check opts getPkgMkDoc $ \fs -> runIO $ do
52 mapM_ (documentPkg opts) fs
53 check opts getPkgTest $ \fs -> runIO $ do
55 codes <- mapM (testPkg opts) fs
56 -- check if any of the tests exited with an exit code other
57 -- than zero; if they did, exit with exit code 1
58 unless (null $ filter (/= ExitSuccess) codes) $
59 exitWith (ExitFailure 1)
61 check opts getPkg $ \fs -> runIO $ do
62 mapM_ (buildPkg opts (WarnOnly `elem` opts)) fs
63 check opts getPkgREPL $ \fs -> case fs of
64 [f] -> replPkg opts f
65 _ -> ifail "Too many packages"
67-- | The main function for the Idris executable.
68runIdris :: [Opt] -> Idris ()
69runIdris opts = do
70 runIO setupBundledCC
71 processShowOptions opts -- Show information then quit.
72 processClientOptions opts -- Be a client to a REPL server.
73 processPackageOptions opts -- Work with Idris packages.
74 idrisMain opts -- Launch REPL or compile mode.
76-- Main program reads command line options, parses the main program, and gets
77-- on with the REPL.
78main :: IO ()
79main = do
80 opts <- runArgParser
81 runMain (runIdris opts)