git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Resolves #883. Look in home directory (after pwd) for '.psci'
a701868Michael Gilliland
psci/PSCi.hs+24−12
@@ -91,12 +91,15 @@ supportModule =
91
91
92-- File helpers
92-- File helpers
93
93
94+onFirstFileMatching :: Monad m => (b -> m (Maybe a)) -> [b] -> m (Maybe a)
95+onFirstFileMatching f pathVariants = runMaybeT . msum $ map (MaybeT . f) pathVariants
96+
94-- |
97-- |
95-- Locates the node executable.
98-- Locates the node executable.
96-- Checks for either @nodejs@ or @node@.
99-- Checks for either @nodejs@ or @node@.
97--
100--
98findNodeProcess :: IO (Maybe String)
101findNodeProcess :: IO (Maybe String)
99−findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
102+findNodeProcess = onFirstFileMatching findExecutable names
100 where names = ["nodejs", "node"]
103 where names = ["nodejs", "node"]
101
104
102-- |
105-- |
@@ -486,18 +489,27 @@ whenFileExists filePath f = do
486 then f absPath
489 then f absPath
487 else PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
490 else PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
488
491
492+-- |
493+-- Attempts to read initial commands from '.psci' in the present working
494+-- directory then the user's home
495+--
489loadUserConfig :: IO (Maybe [Command])
496loadUserConfig :: IO (Maybe [Command])
490−loadUserConfig = do
497+loadUserConfig = onFirstFileMatching readCommands pathGetters
498+ where
499+ pathGetters = [getCurrentDirectory, getHomeDirectory]
500+ readCommands :: IO FilePath -> IO (Maybe [Command])
501+ readCommands path = do
491− configFile <- (</> ".psci") <$> getCurrentDirectory
502+ configFile <- (</> ".psci") <$> path
492− exists <- doesFileExist configFile
503+ exists <- doesFileExist configFile
493− if exists
504+ if exists
494− then do
505+ then do
495− ls <- lines <$> readFile configFile
506+ ls <- lines <$> readFile configFile
496− case mapM parseCommand ls of
507+ case mapM parseCommand ls of
497− Left err -> print err >> exitFailure
508+ Left err -> print err >> exitFailure
498− Right cs -> return $ Just cs
509+ Right cs -> return $ Just cs
499− else
510+ else
500− return Nothing
511+ return Nothing
512+
501
513
502-- | Checks if the Console module is defined
514-- | Checks if the Console module is defined
503consoleIsDefined :: [P.Module] -> Bool
515consoleIsDefined :: [P.Module] -> Bool