@@ -1,8 +1,7 @@
1module Main where
1module Main where
3−import System.Exit ( exitSuccess )
5import Control.Monad ( when )
3import Control.Monad ( when )
4+import System.Exit ( exitSuccess )
7import Idris.AbsSyntax
6import Idris.AbsSyntax
8import Idris.Error
7import Idris.Error
@@ -14,63 +13,60 @@ import Idris.Main
15import Util.System ( setupBundledCC )
14import Util.System ( setupBundledCC )
16+processShowOptions :: [Opt] -> Idris ()
17+processShowOptions opts = runIO $ do
18+ when (ShowAll `elem` opts) $ showExitIdrisInfo
19+ when (ShowLoggingCats `elem` opts) $ showExitIdrisLoggingCategories
20+ when (ShowIncs `elem` opts) $ showExitIdrisFlagsInc
21+ when (ShowLibs `elem` opts) $ showExitIdrisFlagsLibs
22+ when (ShowLibdir `elem` opts) $ showExitIdrisLibDir
23+ when (ShowPkgs `elem` opts) $ showExitIdrisInstalledPackages
25+check :: [Opt] -> (Opt -> Maybe a) -> ([a] -> Idris ()) -> Idris ()
26+check opts extractOpts action = do
27+ case opt extractOpts opts of
19−-- Main program reads command line options, parses the main program, and gets
32+processClientOptions :: [Opt] -> Idris ()
20−-- on with the REPL.
33+processClientOptions opts = check opts getClient $ \fs -> case fs of
38+ Just DontListen -> ifail "\"--client\" and \"--port none\" are incompatible"
39+ Just (ListenPort port) -> runIO $ runClient (Just port) c
40+ Nothing -> runIO $ runClient Nothing c
22−main :: IO ()
42+processPackageOptions :: [Opt] -> Idris ()
23−main = do opts <- runArgParser
43+processPackageOptions opts = do
24− runMain (runIdris opts)
44+ check opts getPkgCheck $ \fs -> runIO $ do
45+ mapM_ (checkPkg opts (WarnOnly `elem` opts) True) fs
46+ check opts getPkgClean $ \fs -> runIO $ do
47+ mapM_ (cleanPkg opts) fs
48+ check opts getPkgMkDoc $ \fs -> runIO $ do
49+ mapM_ (documentPkg opts) fs
50+ check opts getPkgTest $ \fs -> runIO $ do
51+ mapM_ (testPkg opts) fs
52+ check opts getPkg $ \fs -> runIO $ do
53+ mapM_ (buildPkg opts (WarnOnly `elem` opts)) fs
54+ check opts getPkgREPL $ \fs -> case fs of
55+ [f] -> replPkg opts f
56+ _ -> ifail "Too many packages"
26-- | The main function for the Idris executable.
58-- | The main function for the Idris executable.
27runIdris :: [Opt] -> Idris ()
59runIdris :: [Opt] -> Idris ()
28runIdris opts = do
60runIdris opts = do
29− runIO setupBundledCC
61+ runIO setupBundledCC
30− -- Show information then quit.
62+ processShowOptions opts -- Show information then quit.
31− when (ShowAll `elem` opts) $ runIO showExitIdrisInfo
32− when (ShowLoggingCats `elem` opts) $ runIO showExitIdrisLoggingCategories
33− when (ShowIncs `elem` opts) $ runIO showExitIdrisFlagsInc
34− when (ShowLibs `elem` opts) $ runIO showExitIdrisFlagsLibs
35− when (ShowLibdir `elem` opts) $ runIO showExitIdrisLibDir
36− when (ShowPkgs `elem` opts) $ runIO showExitIdrisInstalledPackages
38− -- Be a client to an IDE Mode server.
63+ processClientOptions opts -- Be a client to an IDE Mode server.
39− case opt getClient opts of
41− (c:_) -> do setVerbose False
45− ifail "\"--client\" and \"--port none\" are incompatible"
46− Just (ListenPort port) -> runIO $ runClient (Just port) c
47− Nothing -> runIO $ runClient Nothing c
50− -- Work with Idris packages.
64+ processPackageOptions opts -- Work with Idris packages.
51− case opt getPkgCheck opts of
65+ idrisMain opts -- Launch REPL or compile mode.
53− fs -> do runIO $ mapM_ (checkPkg opts (WarnOnly `elem` opts) True) fs
55− case opt getPkgClean opts of
57− fs -> do runIO $ mapM_ (cleanPkg opts) fs
59− case opt getPkgMkDoc opts of -- IdrisDoc
61− fs -> do runIO $ mapM_ (documentPkg opts) fs
63− case opt getPkgTest opts of
65− fs -> do runIO $ mapM_ (testPkg opts) fs
68− -- Either launch one of the interaction modes, or install a
70− case opt getPkg opts of
71− [] -> case opt getPkgREPL opts of
73− [f] -> replPkg opts f
74− _ -> ifail "Too many packages"
75− fs -> runIO $ mapM_ (buildPkg opts (WarnOnly `elem` opts)) fs
67+-- Main program reads command line options, parses the main program, and gets
72+ runMain (runIdris opts)