cosmetic change.

This commit is contained in:
Kazu Yamamoto 2011-11-02 10:43:34 +09:00
parent fde88dedd1
commit 82e7c6862f

View File

@ -1,7 +1,9 @@
{-# LANGUAGE DoAndIfThenElse #-}
module CabalDev (modifyOptions) where module CabalDev (modifyOptions) where
{- {-
If the directory 'cabal-dev/packages-X.X.X.conf' exists, add it to the If the directory 'cabal-dev/packages-X.X.X.conf' exists, add it to the
options ghc-mod uses to check the source. Otherwise just pass it on. options ghc-mod uses to check the source. Otherwise just pass it on.
-} -}
@ -17,9 +19,9 @@ modifyOptions :: Options -> IO Options
modifyOptions opts = modifyOptions opts =
fmap (has_cdev opts) findCabalDev fmap (has_cdev opts) findCabalDev
where where
has_cdev :: Options -> Maybe String -> Options has_cdev :: Options -> Maybe String -> Options
has_cdev op Nothing = op has_cdev op Nothing = op
has_cdev op (Just path) = addPath op path has_cdev op (Just path) = addPath op path
findCabalDev :: IO (Maybe String) findCabalDev :: IO (Maybe String)
findCabalDev = findCabalDev =
@ -28,18 +30,16 @@ findCabalDev =
addPath :: Options -> String -> Options addPath :: Options -> String -> Options
addPath orig_opts path = do addPath orig_opts path = do
let orig_paths = packageConfs orig_opts let orig_paths = packageConfs orig_opts
orig_opts { orig_opts { packageConfs = orig_paths ++ [path] }
packageConfs = orig_paths ++ [path] }
searchIt :: [FilePath] -> IO (Maybe FilePath) searchIt :: [FilePath] -> IO (Maybe FilePath)
searchIt [] = return Nothing searchIt [] = return Nothing
searchIt path = do searchIt path = do
a <- doesDirectoryExist (mpath path) a <- doesDirectoryExist (mpath path)
case a of if a then do
False -> return Nothing b <- find always (fileName ~~? "packages*.conf") $ mpath path
True -> do maybe (searchIt $ init path) (return . Just) $ listToMaybe b
b <- find always (fileName ~~? "packages*.conf") $ mpath path else
maybe (searchIt $ init path) (return . Just) $ listToMaybe b return Nothing
where where
mpath a = (joinPath a) ++ "cabal-dev/" mpath a = joinPath a ++ "cabal-dev/"