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