diff --git a/app/ghcup/Main.hs b/app/ghcup/Main.hs index f2646fa..96b5e8e 100644 --- a/app/ghcup/Main.hs +++ b/app/ghcup/Main.hs @@ -596,14 +596,14 @@ rmParser = <> command "cabal" ( RmCabal - <$> (info (versionParser' <**> helper) + <$> (info (versionParser' False (Just ListInstalled) (Just Cabal) <**> helper) (progDesc "Remove Cabal version") ) ) <> command "hls" ( RmHLS - <$> (info (versionParser' <**> helper) + <$> (info (versionParser' False (Just ListInstalled) (Just HLS) <**> helper) (progDesc "Remove haskell-language-server version") ) ) @@ -795,6 +795,11 @@ versionCompleter networkSensitive criteria tool = runLogger = myLoggerT loggerConfig + downloadWithUserSource = do + userConf <- runE @'[ JSONError ] ghcupConfigFile + getDownloadsF $ + veitherCont (const GHCupURL) (fromMaybe GHCupURL . uUrlSource) userConf + mpFreq <- runLogger . runE $ platformRequest @@ -811,11 +816,11 @@ versionCompleter networkSensitive criteria tool = mGhcUpInfo <- runEnv . runE $ - if networkSensitive then - getDownloadsF GHCupURL + if networkSensitive then do + downloadWithUserSource else catchE - (\(FileDoesNotExistError _) -> getDownloadsF GHCupURL) + (\(FileDoesNotExistError _) -> downloadWithUserSource) readFromCache forFold mGhcUpInfo $ \(GHCupInfo _ dls) -> do @@ -833,10 +838,10 @@ versionParser = option (short 'v' <> long "version" <> metavar "VERSION" <> help "The target version" ) -versionParser' :: Parser Version -versionParser' = argument +versionParser' :: Bool -> Maybe ListCriteria -> Maybe Tool -> Parser Version +versionParser' networkSensitive criteria tool = argument (eitherReader (first show . version . T.pack)) - (metavar "VERSION") + (metavar "VERSION" <> foldMap (completer . versionCompleter networkSensitive criteria) tool) tagEither :: String -> Either String Tag diff --git a/lib/GHCup/Utils/Dirs.hs b/lib/GHCup/Utils/Dirs.hs index 0c2df15..67d394d 100644 --- a/lib/GHCup/Utils/Dirs.hs +++ b/lib/GHCup/Utils/Dirs.hs @@ -185,9 +185,9 @@ getDirs = do ghcupConfigFile :: (MonadIO m) => Excepts '[JSONError] m UserSettings ghcupConfigFile = do - confDir <- liftIO $ ghcupConfigDir + confDir <- liftIO ghcupConfigDir let file = confDir [rel|config.yaml|] - bs <- liftIO $ handleIO' NoSuchThing (\_ -> pure $ Nothing) $ fmap Just $ readFile file + bs <- liftIO $ handleIO' NoSuchThing (\_ -> pure Nothing) $ Just <$> readFile file case bs of Nothing -> pure defaultUserSettings Just bs' -> lE' JSONDecodeError . bimap show id . Y.decodeEither' . L.toStrict $ bs'