1616{-# LANGUAGE DoAndIfThenElse #-}
1717{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1818{-# LANGUAGE RecordWildCards #-}
19+ {-# LANGUAGE TupleSections #-}
1920
2021module PSCi where
2122
@@ -491,14 +492,20 @@ loop PSCiOptions{..} = do
491492 Right modules -> do
492493 historyFilename <- getHistoryFilename
493494 let settings = defaultSettings { historyFile = Just historyFilename }
494- flip evalStateT (PSCiState psciInputFile defaultImports modules [] psciInputNodeFlags) . runInputT (setComplete completion settings) $ do
495- outputStrLn prologueMessage
496- traverse_ (mapM_ (runPSCI . handleCommand)) config
497- unless (consoleIsDefined (map snd modules)) . outputStrLn $ unlines
498- [ " PSCi requires the purescript-console module to be installed."
499- , " For help getting started, visit http://wiki.purescript.org/PSCi"
500- ]
501- go
495+ foreignsOrError <- runMake $ do
496+ foreignFiles <- forM psciForeignInputFiles (\ inFile -> (inFile,) <$> makeIO (const (P. SimpleErrorWrapper $ P. CannotReadFile inFile)) (readFile inFile))
497+ P. parseForeignModulesFromFiles foreignFiles
498+ case foreignsOrError of
499+ Left errs -> putStrLn (P. prettyPrintMultipleErrors False errs) >> exitFailure
500+ Right foreigns ->
501+ flip evalStateT (PSCiState psciInputFile defaultImports modules foreigns [] psciInputNodeFlags) . runInputT (setComplete completion settings) $ do
502+ outputStrLn prologueMessage
503+ traverse_ (mapM_ (runPSCI . handleCommand)) config
504+ unless (consoleIsDefined (map snd modules)) . outputStrLn $ unlines
505+ [ " PSCi requires the purescript-console module to be installed."
506+ , " For help getting started, visit http://wiki.purescript.org/PSCi"
507+ ]
508+ go
502509 where
503510 go :: InputT (StateT PSCiState IO ) ()
504511 go = do
@@ -520,6 +527,12 @@ inputFile = strArgument $
520527 metavar " FILE"
521528 <> Opts. help " Optional .purs files to load on start"
522529
530+ inputForeignFile :: Parser FilePath
531+ inputForeignFile = strOption $
532+ short ' f'
533+ <> long " ffi"
534+ <> help " The input .js file(s) providing foreign import implementations"
535+
523536nodeFlagsFlag :: Parser [String ]
524537nodeFlagsFlag = option parser $
525538 long " node-opts"
@@ -532,6 +545,7 @@ nodeFlagsFlag = option parser $
532545psciOptions :: Parser PSCiOptions
533546psciOptions = PSCiOptions <$> multiLineMode
534547 <*> many inputFile
548+ <*> many inputForeignFile
535549 <*> nodeFlagsFlag
536550
537551runPSCi :: IO ()
0 commit comments