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