refactoring.

This commit is contained in:
Kazu Yamamoto 2013-02-15 10:47:45 +09:00
parent 7ee8843a52
commit 725566bd44

View File

@ -21,29 +21,30 @@ modifyOptions opts = found ||> notFound
notFound = return opts notFound = return opts
findCabalDev :: Maybe String -> IO FilePath findCabalDev :: Maybe String -> IO FilePath
findCabalDev Nothing = getCurrentDirectory >>= searchIt . splitPath
findCabalDev (Just path) = do findCabalDev (Just path) = do
exist <- doesDirectoryExist path exist <- doesDirectoryExist path
if exist then if exist then
findConf path findConf path
else else
findCabalDev Nothing findCabalDev Nothing
findCabalDev Nothing = getCurrentDirectory >>= searchIt . splitPath
addPath :: Options -> String -> Options addPath :: Options -> String -> Options
addPath orig_opts path = do addPath orig_opts path = orig_opts { ghcOpts = opts' }
let orig_ghcopt = ghcOpts orig_opts where
orig_opts { ghcOpts = orig_ghcopt ++ ["-package-conf", path, "-no-user-package-conf"] } orig_ghcopt = ghcOpts orig_opts
opts' = orig_ghcopt ++ ["-package-conf", path, "-no-user-package-conf"]
searchIt :: [FilePath] -> IO FilePath searchIt :: [FilePath] -> IO FilePath
searchIt [] = throwIO $ userError "Not found" searchIt [] = throwIO $ userError "Not found"
searchIt path = do searchIt path = do
let cabalDir = mpath path
exist <- doesDirectoryExist cabalDir exist <- doesDirectoryExist cabalDir
if exist then if exist then
findConf cabalDir findConf cabalDir
else else
searchIt $ init path searchIt $ init path
where where
cabalDir = mpath path
mpath a = joinPath a </> "cabal-dev/" mpath a = joinPath a </> "cabal-dev/"
findConf :: FilePath -> IO FilePath findConf :: FilePath -> IO FilePath