From 2e3dceecf868a66cb66d2ce1604f9ee785254625 Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Wed, 23 Jun 2021 10:08:06 +0530 Subject: [PATCH] abstracts out getting ghcup conf file path --- lib/GHCup/Utils/Dirs.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/GHCup/Utils/Dirs.hs b/lib/GHCup/Utils/Dirs.hs index ba90660..0057f1e 100644 --- a/lib/GHCup/Utils/Dirs.hs +++ b/lib/GHCup/Utils/Dirs.hs @@ -26,6 +26,7 @@ module GHCup.Utils.Dirs , parseGHCupGHCDir , relativeSymlink , withGHCupTmpDir + , getConfigFilePath ) where @@ -201,13 +202,16 @@ getDirs = do --[ GHCup files ]-- ------------------- +getConfigFilePath :: (MonadIO m) => m FilePath +getConfigFilePath = do + confDir <- liftIO ghcupConfigDir + pure $ confDir "config.yaml" ghcupConfigFile :: (MonadIO m) => Excepts '[JSONError] m UserSettings ghcupConfigFile = do - confDir <- liftIO ghcupConfigDir - let file = confDir "config.yaml" - contents <- liftIO $ handleIO' NoSuchThing (\_ -> pure Nothing) $ Just <$> BS.readFile file + filepath <- getConfigFilePath + contents <- liftIO $ handleIO' NoSuchThing (\_ -> pure Nothing) $ Just <$> BS.readFile filepath case contents of Nothing -> pure defaultUserSettings Just contents' -> lE' JSONDecodeError . first show . Y.decodeEither' $ contents'