From 107fed6e609ec808c3ee14c438733314fe9c4973 Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Mon, 30 Aug 2021 15:18:43 +0530 Subject: [PATCH] refactor nested case statements when installing cabal --- lib/GHCup.hs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 8813e2a..f75a99b 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -425,22 +425,23 @@ installCabalBindist dlinfo ver isoFilepath forceInstall = do -- check if we already have a regular cabal already installed regularCabalInstalled <- checkIfCabalInstalled ver binDir exeExt - case forceInstall of - True -> case isoFilepath of - Nothing -> -- force install and a regular install - when (regularCabalInstalled) - (do - lift $ $(logInfo) $ "Removing the currently installed version first!" - liftE $ rmCabalVer ver) - - _ -> pure () -- force install and an isolated install (checks done later while unpacking) + -- check if we already have a regular cabal already installed + regularCabalInstalled <- lift $ checkIfToolInstalled Cabal ver + + if + | forceInstall + , regularCabalInstalled + , Nothing <- isoFilepath -> do + lift $ $(logInfo) $ "Removing the currently installed version first!" + liftE $ rmCabalVer ver + + | not forceInstall + , regularCabalInstalled + , Nothing <- isoFilepath -> do + throwE $ AlreadyInstalled Cabal ver + + | otherwise -> pure () - False -> case isoFilepath of - Nothing -> - when (regularCabalInstalled) - (throwE $ AlreadyInstalled Cabal ver) - - _ -> pure () -- download (or use cached version) dl <- liftE $ downloadCached dlinfo Nothing