ghcup-0.1.50.0: ghc toolchain installer
Safe HaskellSafe-Inferred
LanguageHaskell2010

GHCup.Utils.Parsers

Synopsis

Documentation

>>> :set -XOverloadedStrings
>>> :set -XDataKinds
>>> :set -XTypeApplications
>>> :set -XQuasiQuotes
>>> import System.Directory
>>> import URI.ByteString
>>> import qualified Data.Text as T
>>> import GHCup.Prelude
>>> import GHCup.Download
>>> import GHCup.Version
>>> import GHCup.Errors
>>> import GHCup.Types
>>> import GHCup.Utils.Dirs
>>> import GHCup.Types.Optics
>>> import Data.Versions
>>> import Optics
>>> import GHCup.Prelude.Version.QQ
>>> import qualified Data.Text.Encoding as E
>>> import qualified Data.Map.Strict               as M
>>> import Control.Monad.Reader
>>> import Data.Variant.Excepts
>>> import Text.PrettyPrint.HughesPJClass ( prettyShow )
>>> let lc = LoggerConfig { lcPrintDebug = False, consoleOutter = mempty, fileOutter = mempty, fancyColors = False }
>>> dirs' <- getAllDirs
>>> let installedVersions = [ ([pver|8.10.7|], "-debug+lol", Nothing), ([pver|8.10.4|], "", Nothing), ([pver|8.8.4|], "", Nothing), ([pver|8.8.3|], "", Nothing) ]
>>> let settings = defaultSettings { cache = True, metaCache = 0, noNetwork = True }
>>> let leanAppState = LeanAppState settings dirs' defaultKeyBindings lc
>>> cwd <- getCurrentDirectory
>>> (Right ref) <- pure $ GHCup.Utils.parseURI $ "file://" <> E.encodeUtf8 (T.pack cwd) <> "/data/metadata/" <> (urlBaseName . view pathL' $ ghcupURL)
>>> (Right ref') <- pure $ GHCup.Utils.parseURI $ "file://" <> E.encodeUtf8 (T.pack cwd) <> "/data/metadata/" <> (urlBaseName . view pathL' $ channelURL PrereleasesChannel)
>>> (VRight r) <- (fmap . fmap) _ghcupDownloads $ flip runReaderT leanAppState . runE @'[DigestError, GPGError, JSONError , DownloadFailed , FileDoesNotExistError, ContentLengthError] $ liftE (getBase ref) >>= liftE . decodeMetadata @GHCupInfo
>>> (VRight r') <- (fmap . fmap) _ghcupDownloads $ flip runReaderT leanAppState . runE @'[DigestError, GPGError, JSONError , DownloadFailed , FileDoesNotExistError, ContentLengthError] $ liftE (getBase ref') >>= liftE . decodeMetadata @GHCupInfo
>>> let rr = M.unionsWith (M.unionWith (\_ b2 -> b2)) [r, r']
>>> let go = flip runReaderT leanAppState . fmap (tVerToText . fst)

guessFullVersion :: (HasLog env, MonadFail m, MonadReader env m, HasDirs env, MonadThrow m, MonadIO m, MonadCatch m) => GHCupDownloads -> GHCTargetVersion -> Tool -> GuessMode -> m (GHCTargetVersion, Maybe VersionInfo) Source #

Guess the full version from an input version, by possibly examining the metadata and the installed versions.

>>> go $ guessFullVersion rr (mkTVer [vver|8|]) GHC GLax
"8.10.7"
>>> go $ guessFullVersion rr (mkTVer [vver|8.10|]) GHC GLax
"8.10.7"
>>> go $ guessFullVersion rr (mkTVer [vver|8.10.7|]) GHC GLax
"8.10.7"
>>> go $ guessFullVersion rr (mkTVer [vver|9.12.1|]) GHC GLax
"9.12.1"
>>> go $ guessFullVersion rr (mkTVer [vver|8|]) GHC GStrict
"8"

Orphan instances

Alternative (Either [a]) Source # 
Instance details

Methods

empty :: Either [a] a0 #

(<|>) :: Either [a] a0 -> Either [a] a0 -> Either [a] a0 #

some :: Either [a] a0 -> Either [a] [a0] #

many :: Either [a] a0 -> Either [a] [a0] #