1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-19 04:41:36 +03:00
juvix/app/Main.hs

36 lines
1.1 KiB
Haskell
Raw Normal View History

{-# LANGUAGE QuasiQuotes #-}
2022-01-18 14:25:42 +03:00
module Main (main) where
import App
2022-09-14 17:16:15 +03:00
import CommonOptions
import Data.String.Interpolate (i)
import GlobalOptions
import Juvix.Compiler.Pipeline.Root
2022-09-14 17:16:15 +03:00
import TopCommand
import TopCommand.Options
2022-09-14 17:16:15 +03:00
main :: IO ()
main = do
let parserPreferences = prefs showHelpOnEmpty
invokeDir <- getCurrentDir
(_runAppIOArgsGlobalOptions, cli) <- customExecParser parserPreferences descr
mbuildDir <- mapM (prepathToAbsDir invokeDir) (_runAppIOArgsGlobalOptions ^? globalBuildDir . _Just . pathPath)
mainFile <- topCommandInputPath cli
mapM_ checkMainFile mainFile
runFinal
. resourceToIOFinal
. embedToFinal @IO
. runTaggedLockPermissive
$ do
_runAppIOArgsRoot <- findRootAndChangeDir (containingDir <$> mainFile) mbuildDir invokeDir
runAppIO RunAppIOArgs {..} (runTopCommand cli)
where
checkMainFile :: SomePath b -> IO ()
checkMainFile p = unlessM (doesSomePathExist p) err
where
err :: IO ()
err = do
hPutStrLn stderr [i|The input path #{p} does not exist|]
exitFailure