git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #899 from MichaelXavier/psci-node-flags

Psci node flags

commitdd4ca07826802324914a69d0073f8b05238a84e1 authorPhil Freeman <paf31@cantab.net> dateFri 20 Feb 2015, 22:10 (12 years ago) parent7bc1490f0d351f
1 file changed+15−3
psci/Main.hs+15−3
psci/Main.hs+15−3
@@ -58,8 +58,9 @@ import Commands as C
5858import Parser
5959
6060data PSCiOptions = PSCiOptions
61− { psciMultiLineMode :: Bool
61+ { psciMultiLineMode :: Bool
6262 , psciInputFile :: [FilePath]
63+ , psciInputNodeFlags :: [String]
6364 }
6465
6566-- |
@@ -73,6 +74,7 @@ data PSCiState = PSCiState
7374 , psciImportedModuleNames :: [P.ModuleName]
7475 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
7576 , psciLetBindings :: [P.Declaration]
77+ , psciNodeFlags :: [String]
7678 }
7779
7880-- State helpers
@@ -401,13 +403,14 @@ handleDeclaration :: P.Expr -> PSCI ()
401403handleDeclaration val = do
402404 st <- PSCI $ lift get
403405 let m = createTemporaryModule True st val
406+ let nodeArgs = psciNodeFlags st ++ [indexFile]
404407 e <- psciIO . runMake $ P.make modulesDir (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
405408 case e of
406409 Left err -> PSCI $ outputStrLn err
407410 Right _ -> do
408411 psciIO $ writeFile indexFile "require('$PSCI').main();"
409412 process <- psciIO findNodeProcess
410− result <- psciIO $ traverse (\node -> readProcessWithExitCode node [indexFile] "") process
413+ result <- psciIO $ traverse (\node -> readProcessWithExitCode node nodeArgs "") process
411414 case result of
412415 Just (ExitSuccess, out, _) -> PSCI $ outputStrLn out
413416 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
@@ -608,7 +611,7 @@ loop PSCiOptions{..} = do
608611 Right modules -> do
609612 historyFilename <- getHistoryFilename
610613 let settings = defaultSettings { historyFile = Just historyFilename }
611− flip evalStateT (PSCiState psciInputFile defaultImports modules []) . runInputT (setComplete completion settings) $ do
614+ flip evalStateT (PSCiState psciInputFile defaultImports modules [] psciInputNodeFlags) . runInputT (setComplete completion settings) $ do
612615 outputStrLn prologueMessage
613616 traverse_ (mapM_ (runPSCI . handleCommand)) config
614617 go
@@ -633,9 +636,18 @@ inputFile = strArgument $
633636 metavar "FILE"
634637 <> Opts.help "Optional .purs files to load on start"
635638
639+nodeFlagsFlag :: Parser [String]
640+nodeFlagsFlag = option parser $
641+ long "node-opts"
642+ <> metavar "NODE_OPTS"
643+ <> Opts.help "Flags to pass to node, separated by spaces"
644+ where
645+ parser = words <$> str
646+
636647psciOptions :: Parser PSCiOptions
637648psciOptions = PSCiOptions <$> multiLineMode
638649 <*> many inputFile
650+ <*> nodeFlagsFlag
639651
640652main :: IO ()
641653main = execParser opts >>= loop