{-# LANGUAGE CPP                   #-}
{-# LANGUAGE DataKinds             #-}
{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}

{-|
Module      : GHCup.List
Description : Listing versions and tools
Copyright   : (c) Julian Ospald, 2020
License     : LGPL-3.0
Maintainer  : hasufell@hasufell.de
Stability   : experimental
Portability : portable
-}
module GHCup.List where

import           GHCup.Download
import           GHCup.Errors
import           GHCup.Types
import           GHCup.Types.JSON               ( )
import           GHCup.Types.Optics
import           GHCup.Utils
import           GHCup.Prelude.Logger
import           GHCup.Version

import           Control.Applicative
import           Control.Exception.Safe
import           Control.Monad
#if !MIN_VERSION_base(4,13,0)
import           Control.Monad.Fail             ( MonadFail )
#endif
import           Control.Monad.Reader
import           Data.Either
import           Data.List
import           Data.Maybe
import           Data.Text                      ( Text )
import           Data.Time.Calendar             ( Day )
import           Data.Versions                hiding ( patch )
import           Haskus.Utils.Variant.Excepts
import           Optics
import           Prelude                 hiding ( abs
                                                , writeFile
                                                )

import qualified Data.Map.Strict               as Map
import qualified Data.Text                     as T










    ------------------
    --[ List tools ]--
    ------------------


-- | Filter data type for 'listVersions'.
data ListCriteria = ListInstalled  Bool
                  | ListSet        Bool
                  | ListAvailable  Bool
                  deriving Int -> ListCriteria -> ShowS
[ListCriteria] -> ShowS
ListCriteria -> String
forall (a :: OpticKind).
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListCriteria] -> ShowS
$cshowList :: [ListCriteria] -> ShowS
show :: ListCriteria -> String
$cshow :: ListCriteria -> String
showsPrec :: Int -> ListCriteria -> ShowS
$cshowsPrec :: Int -> ListCriteria -> ShowS
Show

-- | A list result describes a single tool version
-- and various of its properties.
data ListResult = ListResult
  { ListResult -> Tool
lTool      :: Tool
  , ListResult -> Version
lVer       :: Version
  , ListResult -> Maybe Text
lCross     :: Maybe Text -- ^ currently only for GHC
  , ListResult -> [Tag]
lTag       :: [Tag]
  , ListResult -> Bool
lInstalled :: Bool
  , ListResult -> Bool
lSet       :: Bool -- ^ currently active version
  , ListResult -> Bool
fromSrc    :: Bool -- ^ compiled from source
  , ListResult -> Bool
lStray     :: Bool -- ^ not in download info
  , ListResult -> Bool
lNoBindist :: Bool -- ^ whether the version is available for this platform/arch
  , ListResult -> Bool
hlsPowered :: Bool
  , ListResult -> Maybe Day
lReleaseDay :: Maybe Day
  }
  deriving (ListResult -> ListResult -> Bool
forall (a :: OpticKind).
(a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListResult -> ListResult -> Bool
$c/= :: ListResult -> ListResult -> Bool
== :: ListResult -> ListResult -> Bool
$c== :: ListResult -> ListResult -> Bool
Eq, Eq ListResult
ListResult -> ListResult -> Bool
ListResult -> ListResult -> Ordering
ListResult -> ListResult -> ListResult
forall (a :: OpticKind).
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ListResult -> ListResult -> ListResult
$cmin :: ListResult -> ListResult -> ListResult
max :: ListResult -> ListResult -> ListResult
$cmax :: ListResult -> ListResult -> ListResult
>= :: ListResult -> ListResult -> Bool
$c>= :: ListResult -> ListResult -> Bool
> :: ListResult -> ListResult -> Bool
$c> :: ListResult -> ListResult -> Bool
<= :: ListResult -> ListResult -> Bool
$c<= :: ListResult -> ListResult -> Bool
< :: ListResult -> ListResult -> Bool
$c< :: ListResult -> ListResult -> Bool
compare :: ListResult -> ListResult -> Ordering
$ccompare :: ListResult -> ListResult -> Ordering
Ord, Int -> ListResult -> ShowS
[ListResult] -> ShowS
ListResult -> String
forall (a :: OpticKind).
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListResult] -> ShowS
$cshowList :: [ListResult] -> ShowS
show :: ListResult -> String
$cshow :: ListResult -> String
showsPrec :: Int -> ListResult -> ShowS
$cshowsPrec :: Int -> ListResult -> ShowS
Show)


-- | Extract all available tool versions and their tags.
availableToolVersions :: GHCupDownloads -> Tool -> Map.Map GHCTargetVersion VersionInfo
availableToolVersions :: GHCupDownloads -> Tool -> Map GHCTargetVersion VersionInfo
availableToolVersions GHCupDownloads
av Tool
tool = forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (a :: OpticKind).
Is k A_Getter =>
Optic' k is s a -> s -> a
view
  (forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at Tool
tool forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (a :: OpticKind). Eq a => a -> Iso' (Maybe a) a
non forall (k :: OpticKind) (a :: OpticKind). Map k a
Map.empty)
  GHCupDownloads
av


-- | List all versions from the download info, as well as stray
-- versions.
listVersions :: ( MonadCatch m
                             , HasLog env
                             , MonadThrow m
                             , HasLog env
                             , MonadIO m
                             , MonadReader env m
                             , HasDirs env
                             , HasPlatformReq env
                             , HasGHCupInfo env
                             )
                          => Maybe Tool
                          -> [ListCriteria]
                          -> Bool
                          -> Bool
                          -> (Maybe Day, Maybe Day)
                          -> m [ListResult]
listVersions :: forall (m :: OpticKind -> OpticKind) (env :: OpticKind).
(MonadCatch m, HasLog env, MonadThrow m, HasLog env, MonadIO m,
 MonadReader env m, HasDirs env, HasPlatformReq env,
 HasGHCupInfo env) =>
Maybe Tool
-> [ListCriteria]
-> Bool
-> Bool
-> (Maybe Day, Maybe Day)
-> m [ListResult]
listVersions Maybe Tool
lt' [ListCriteria]
criteria Bool
hideOld Bool
showNightly (Maybe Day, Maybe Day)
days = do
  -- some annoying work to avoid too much repeated IO
  Maybe Version
cSet <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(HasLog env, MonadReader env m, HasDirs env, MonadIO m,
 MonadThrow m, MonadCatch m) =>
m (Maybe Version)
cabalSet
  [Either String Version]
cabals <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadIO m, MonadCatch m) =>
m [Either String Version]
getInstalledCabals
  Maybe Version
hlsSet' <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadIO m, MonadThrow m,
 MonadCatch m) =>
m (Maybe Version)
hlsSet
  [Either String Version]
hlses <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadIO m, MonadCatch m) =>
m [Either String Version]
getInstalledHLSs
  Maybe Version
sSet <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadIO m, MonadThrow m,
 MonadCatch m, HasLog env) =>
m (Maybe Version)
stackSet
  [Either String Version]
stacks <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadIO m, MonadCatch m) =>
m [Either String Version]
getInstalledStacks

  forall {env :: OpticKind} {m :: OpticKind -> OpticKind}.
(MonadReader env m, MonadIO m, MonadCatch m,
 LabelOptic "dirs" A_Lens env env Dirs Dirs,
 LabelOptic "ghcupInfo" A_Lens env env GHCupInfo GHCupInfo,
 LabelOptic "pfreq" A_Lens env env PlatformRequest PlatformRequest,
 LabelOptic
   "loggerConfig" A_Lens env env LoggerConfig LoggerConfig) =>
Maybe Tool
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> m [ListResult]
go Maybe Tool
lt' Maybe Version
cSet [Either String Version]
cabals Maybe Version
hlsSet' [Either String Version]
hlses Maybe Version
sSet [Either String Version]
stacks
 where
  go :: Maybe Tool
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> m [ListResult]
go Maybe Tool
lt Maybe Version
cSet [Either String Version]
cabals Maybe Version
hlsSet' [Either String Version]
hlses Maybe Version
sSet [Either String Version]
stacks = do
    case Maybe Tool
lt of
      Just Tool
t -> do
        GHCupInfo { $sel:_ghcupDownloads:GHCupInfo :: GHCupInfo -> GHCupDownloads
_ghcupDownloads = GHCupDownloads
dls } <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m,
 LabelOptic' "ghcupInfo" A_Lens env GHCupInfo) =>
m GHCupInfo
getGHCupInfo
        -- get versions from GHCupDownloads
        let avTools :: Map GHCTargetVersion VersionInfo
avTools = GHCupDownloads -> Tool -> Map GHCTargetVersion VersionInfo
availableToolVersions GHCupDownloads
dls Tool
t
        [ListResult]
lr <- [ListResult] -> [ListResult]
filter' forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> forall (t :: OpticKind -> OpticKind) (m :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (forall (k :: OpticKind) (a :: OpticKind). Map k a -> [(k, a)]
Map.toList Map GHCTargetVersion VersionInfo
avTools) (forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(HasLog env, MonadReader env m, HasDirs env, HasGHCupInfo env,
 HasPlatformReq env, MonadIO m, MonadCatch m) =>
Tool
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> (GHCTargetVersion, VersionInfo)
-> m ListResult
toListResult Tool
t Maybe Version
cSet [Either String Version]
cabals Maybe Version
hlsSet' [Either String Version]
hlses Maybe Version
sSet [Either String Version]
stacks)

        case Tool
t of
          Tool
GHC -> do
            [ListResult]
slr <- forall (m :: OpticKind -> OpticKind) (env :: OpticKind).
(MonadCatch m, MonadReader env m, HasDirs env, MonadThrow m,
 HasLog env, MonadIO m) =>
Map GHCTargetVersion VersionInfo -> m [ListResult]
strayGHCs Map GHCTargetVersion VersionInfo
avTools
            forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (forall (a :: OpticKind). Ord a => [a] -> [a]
sort ([ListResult]
slr forall (a :: OpticKind). [a] -> [a] -> [a]
++ [ListResult]
lr))
          Tool
Cabal -> do
            [ListResult]
slr <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadCatch m, MonadThrow m,
 HasLog env, MonadIO m) =>
Map Version VersionInfo
-> Maybe Version -> [Either String Version] -> m [ListResult]
strayCabals (forall (k2 :: OpticKind) (k1 :: OpticKind) (a :: OpticKind).
Ord k2 =>
(k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeys GHCTargetVersion -> Version
_tvVersion Map GHCTargetVersion VersionInfo
avTools) Maybe Version
cSet [Either String Version]
cabals
            forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (forall (a :: OpticKind). Ord a => [a] -> [a]
sort ([ListResult]
slr forall (a :: OpticKind). [a] -> [a] -> [a]
++ [ListResult]
lr))
          Tool
HLS -> do
            [ListResult]
slr <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadCatch m, MonadThrow m,
 HasLog env, MonadIO m) =>
Map Version VersionInfo
-> Maybe Version -> [Either String Version] -> m [ListResult]
strayHLS (forall (k2 :: OpticKind) (k1 :: OpticKind) (a :: OpticKind).
Ord k2 =>
(k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeys GHCTargetVersion -> Version
_tvVersion Map GHCTargetVersion VersionInfo
avTools) Maybe Version
hlsSet' [Either String Version]
hlses
            forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (forall (a :: OpticKind). Ord a => [a] -> [a]
sort ([ListResult]
slr forall (a :: OpticKind). [a] -> [a] -> [a]
++ [ListResult]
lr))
          Tool
Stack -> do
            [ListResult]
slr <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadCatch m, MonadThrow m,
 HasLog env, MonadIO m) =>
Map Version VersionInfo
-> Maybe Version -> [Either String Version] -> m [ListResult]
strayStacks (forall (k2 :: OpticKind) (k1 :: OpticKind) (a :: OpticKind).
Ord k2 =>
(k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeys GHCTargetVersion -> Version
_tvVersion Map GHCTargetVersion VersionInfo
avTools) Maybe Version
sSet [Either String Version]
stacks
            forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (forall (a :: OpticKind). Ord a => [a] -> [a]
sort ([ListResult]
slr forall (a :: OpticKind). [a] -> [a] -> [a]
++ [ListResult]
lr))
          Tool
GHCup -> do
            let cg :: [ListResult]
cg = forall (a :: OpticKind). Maybe a -> [a]
maybeToList forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Map GHCTargetVersion VersionInfo -> Maybe ListResult
currentGHCup Map GHCTargetVersion VersionInfo
avTools
            forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (forall (a :: OpticKind). Ord a => [a] -> [a]
sort ([ListResult]
cg forall (a :: OpticKind). [a] -> [a] -> [a]
++ [ListResult]
lr))
      Maybe Tool
Nothing -> do
        [ListResult]
ghcvers   <- Maybe Tool
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> m [ListResult]
go (forall (a :: OpticKind). a -> Maybe a
Just Tool
GHC) Maybe Version
cSet [Either String Version]
cabals Maybe Version
hlsSet' [Either String Version]
hlses Maybe Version
sSet [Either String Version]
stacks
        [ListResult]
cabalvers <- Maybe Tool
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> m [ListResult]
go (forall (a :: OpticKind). a -> Maybe a
Just Tool
Cabal) Maybe Version
cSet [Either String Version]
cabals Maybe Version
hlsSet' [Either String Version]
hlses Maybe Version
sSet [Either String Version]
stacks
        [ListResult]
hlsvers   <- Maybe Tool
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> m [ListResult]
go (forall (a :: OpticKind). a -> Maybe a
Just Tool
HLS) Maybe Version
cSet [Either String Version]
cabals Maybe Version
hlsSet' [Either String Version]
hlses Maybe Version
sSet [Either String Version]
stacks
        [ListResult]
ghcupvers <- Maybe Tool
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> m [ListResult]
go (forall (a :: OpticKind). a -> Maybe a
Just Tool
GHCup) Maybe Version
cSet [Either String Version]
cabals Maybe Version
hlsSet' [Either String Version]
hlses Maybe Version
sSet [Either String Version]
stacks
        [ListResult]
stackvers <- Maybe Tool
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> m [ListResult]
go (forall (a :: OpticKind). a -> Maybe a
Just Tool
Stack) Maybe Version
cSet [Either String Version]
cabals Maybe Version
hlsSet' [Either String Version]
hlses Maybe Version
sSet [Either String Version]
stacks
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([ListResult]
ghcvers forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [ListResult]
cabalvers forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [ListResult]
hlsvers forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [ListResult]
stackvers forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [ListResult]
ghcupvers)
  strayGHCs :: ( MonadCatch m
               , MonadReader env m
               , HasDirs env
               , MonadThrow m
               , HasLog env
               , MonadIO m
               )
            => Map.Map GHCTargetVersion VersionInfo
            -> m [ListResult]
  strayGHCs :: forall (m :: OpticKind -> OpticKind) (env :: OpticKind).
(MonadCatch m, MonadReader env m, HasDirs env, MonadThrow m,
 HasLog env, MonadIO m) =>
Map GHCTargetVersion VersionInfo -> m [ListResult]
strayGHCs Map GHCTargetVersion VersionInfo
avTools = do
    [Either String GHCTargetVersion]
ghcs <- forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadIO m) =>
m [Either String GHCTargetVersion]
getInstalledGHCs
    forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap forall (a :: OpticKind). [Maybe a] -> [a]
catMaybes forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (t :: OpticKind -> OpticKind) (m :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Either String GHCTargetVersion]
ghcs forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \case
      Right tver :: GHCTargetVersion
tver@GHCTargetVersion{ Maybe Text
Version
$sel:_tvTarget:GHCTargetVersion :: GHCTargetVersion -> Maybe Text
_tvVersion :: Version
_tvTarget :: Maybe Text
$sel:_tvVersion:GHCTargetVersion :: GHCTargetVersion -> Version
.. } -> do
        case forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Maybe a
Map.lookup GHCTargetVersion
tver Map GHCTargetVersion VersionInfo
avTools of
          Just VersionInfo
_  -> forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind). Maybe a
Nothing
          Maybe VersionInfo
Nothing -> do
            Bool
lSet    <- forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap (forall (b :: OpticKind) (a :: OpticKind).
b -> (a -> b) -> Maybe a -> b
maybe Bool
False (\(GHCTargetVersion Maybe Text
_ Version
v ) -> Version
v forall (a :: OpticKind). Eq a => a -> a -> Bool
== Version
_tvVersion)) forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadThrow m, MonadIO m) =>
Maybe Text -> m (Maybe GHCTargetVersion)
ghcSet Maybe Text
_tvTarget
            Bool
fromSrc <- forall (m :: OpticKind -> OpticKind) (env :: OpticKind).
(MonadIO m, MonadReader env m, HasDirs env, MonadThrow m) =>
GHCTargetVersion -> m Bool
ghcSrcInstalled GHCTargetVersion
tver
            Bool
hlsPowered <- forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap (forall (t :: OpticKind -> OpticKind) (a :: OpticKind).
(Foldable t, Eq a) =>
a -> t a -> Bool
elem Version
_tvVersion) forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadIO m, MonadThrow m,
 MonadCatch m) =>
m [Version]
hlsGHCVersions
            forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (a :: OpticKind). a -> Maybe a
Just forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ListResult
              { lTool :: Tool
lTool      = Tool
GHC
              , lVer :: Version
lVer       = Version
_tvVersion
              , lCross :: Maybe Text
lCross     = Maybe Text
_tvTarget
              , lTag :: [Tag]
lTag       = []
              , lInstalled :: Bool
lInstalled = Bool
True
              , lStray :: Bool
lStray     = forall (a :: OpticKind). Maybe a -> Bool
isNothing (forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Maybe a
Map.lookup GHCTargetVersion
tver Map GHCTargetVersion VersionInfo
avTools)
              , lNoBindist :: Bool
lNoBindist = Bool
False
              , lReleaseDay :: Maybe Day
lReleaseDay = forall (a :: OpticKind). Maybe a
Nothing
              , Bool
hlsPowered :: Bool
fromSrc :: Bool
lSet :: Bool
hlsPowered :: Bool
fromSrc :: Bool
lSet :: Bool
..
              }
      Left String
e -> do
        forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m,
 LabelOptic' "loggerConfig" A_Lens env LoggerConfig, MonadIO m) =>
Text -> m ()
logWarn
          forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Text
"Could not parse version of stray directory" forall (a :: OpticKind). Semigroup a => a -> a -> a
<> String -> Text
T.pack String
e
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind). Maybe a
Nothing

  strayCabals :: ( MonadReader env m
                 , HasDirs env
                 , MonadCatch m
                 , MonadThrow m
                 , HasLog env
                 , MonadIO m
                 )
            => Map.Map Version VersionInfo
            -> Maybe Version
            -> [Either FilePath Version]
            -> m [ListResult]
  strayCabals :: forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadCatch m, MonadThrow m,
 HasLog env, MonadIO m) =>
Map Version VersionInfo
-> Maybe Version -> [Either String Version] -> m [ListResult]
strayCabals Map Version VersionInfo
avTools Maybe Version
cSet [Either String Version]
cabals = do
    forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap forall (a :: OpticKind). [Maybe a] -> [a]
catMaybes forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (t :: OpticKind -> OpticKind) (m :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Either String Version]
cabals forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \case
      Right Version
ver ->
        case forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Maybe a
Map.lookup Version
ver Map Version VersionInfo
avTools of
          Just VersionInfo
_  -> forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind). Maybe a
Nothing
          Maybe VersionInfo
Nothing -> do
            let lSet :: Bool
lSet = Maybe Version
cSet forall (a :: OpticKind). Eq a => a -> a -> Bool
== forall (a :: OpticKind). a -> Maybe a
Just Version
ver
            forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (a :: OpticKind). a -> Maybe a
Just forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ListResult
              { lTool :: Tool
lTool      = Tool
Cabal
              , lVer :: Version
lVer       = Version
ver
              , lCross :: Maybe Text
lCross     = forall (a :: OpticKind). Maybe a
Nothing
              , lTag :: [Tag]
lTag       = []
              , lInstalled :: Bool
lInstalled = Bool
True
              , lStray :: Bool
lStray     = forall (a :: OpticKind). Maybe a -> Bool
isNothing (forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Maybe a
Map.lookup Version
ver Map Version VersionInfo
avTools)
              , lNoBindist :: Bool
lNoBindist = Bool
False
              , fromSrc :: Bool
fromSrc    = Bool
False -- actually, we don't know :>
              , hlsPowered :: Bool
hlsPowered = Bool
False
              , lReleaseDay :: Maybe Day
lReleaseDay = forall (a :: OpticKind). Maybe a
Nothing
              , Bool
lSet :: Bool
lSet :: Bool
..
              }
      Left String
e -> do
        forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m,
 LabelOptic' "loggerConfig" A_Lens env LoggerConfig, MonadIO m) =>
Text -> m ()
logWarn
          forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Text
"Could not parse version of stray directory" forall (a :: OpticKind). Semigroup a => a -> a -> a
<> String -> Text
T.pack String
e
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind). Maybe a
Nothing

  strayHLS :: ( MonadReader env m
              , HasDirs env
              , MonadCatch m
              , MonadThrow m
              , HasLog env
              , MonadIO m)
           => Map.Map Version VersionInfo
           -> Maybe Version
           -> [Either FilePath Version]
           -> m [ListResult]
  strayHLS :: forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadCatch m, MonadThrow m,
 HasLog env, MonadIO m) =>
Map Version VersionInfo
-> Maybe Version -> [Either String Version] -> m [ListResult]
strayHLS Map Version VersionInfo
avTools Maybe Version
hlsSet' [Either String Version]
hlss = do
    forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap forall (a :: OpticKind). [Maybe a] -> [a]
catMaybes forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (t :: OpticKind -> OpticKind) (m :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Either String Version]
hlss forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \case
      Right Version
ver ->
        case forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Maybe a
Map.lookup Version
ver Map Version VersionInfo
avTools of
          Just VersionInfo
_  -> forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind). Maybe a
Nothing
          Maybe VersionInfo
Nothing -> do
            let lSet :: Bool
lSet = Maybe Version
hlsSet' forall (a :: OpticKind). Eq a => a -> a -> Bool
== forall (a :: OpticKind). a -> Maybe a
Just Version
ver
            forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (a :: OpticKind). a -> Maybe a
Just forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ListResult
              { lTool :: Tool
lTool      = Tool
HLS
              , lVer :: Version
lVer       = Version
ver
              , lCross :: Maybe Text
lCross     = forall (a :: OpticKind). Maybe a
Nothing
              , lTag :: [Tag]
lTag       = []
              , lInstalled :: Bool
lInstalled = Bool
True
              , lStray :: Bool
lStray     = forall (a :: OpticKind). Maybe a -> Bool
isNothing (forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Maybe a
Map.lookup Version
ver Map Version VersionInfo
avTools)
              , lNoBindist :: Bool
lNoBindist = Bool
False
              , fromSrc :: Bool
fromSrc    = Bool
False -- actually, we don't know :>
              , hlsPowered :: Bool
hlsPowered = Bool
False
              , lReleaseDay :: Maybe Day
lReleaseDay = forall (a :: OpticKind). Maybe a
Nothing
              , Bool
lSet :: Bool
lSet :: Bool
..
              }
      Left String
e -> do
        forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m,
 LabelOptic' "loggerConfig" A_Lens env LoggerConfig, MonadIO m) =>
Text -> m ()
logWarn
          forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Text
"Could not parse version of stray directory" forall (a :: OpticKind). Semigroup a => a -> a -> a
<> String -> Text
T.pack String
e
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind). Maybe a
Nothing

  strayStacks :: ( MonadReader env m
                 , HasDirs env
                 , MonadCatch m
                 , MonadThrow m
                 , HasLog env
                 , MonadIO m
                 )
              => Map.Map Version VersionInfo
              -> Maybe Version
              -> [Either FilePath Version]
              -> m [ListResult]
  strayStacks :: forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadCatch m, MonadThrow m,
 HasLog env, MonadIO m) =>
Map Version VersionInfo
-> Maybe Version -> [Either String Version] -> m [ListResult]
strayStacks Map Version VersionInfo
avTools Maybe Version
stackSet' [Either String Version]
stacks = do
    forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap forall (a :: OpticKind). [Maybe a] -> [a]
catMaybes forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (t :: OpticKind -> OpticKind) (m :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Either String Version]
stacks forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \case
      Right Version
ver ->
        case forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Maybe a
Map.lookup Version
ver Map Version VersionInfo
avTools of
          Just VersionInfo
_  -> forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind). Maybe a
Nothing
          Maybe VersionInfo
Nothing -> do
            let lSet :: Bool
lSet = Maybe Version
stackSet' forall (a :: OpticKind). Eq a => a -> a -> Bool
== forall (a :: OpticKind). a -> Maybe a
Just Version
ver
            forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (a :: OpticKind). a -> Maybe a
Just forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ListResult
              { lTool :: Tool
lTool      = Tool
Stack
              , lVer :: Version
lVer       = Version
ver
              , lCross :: Maybe Text
lCross     = forall (a :: OpticKind). Maybe a
Nothing
              , lTag :: [Tag]
lTag       = []
              , lInstalled :: Bool
lInstalled = Bool
True
              , lStray :: Bool
lStray     = forall (a :: OpticKind). Maybe a -> Bool
isNothing (forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Maybe a
Map.lookup Version
ver Map Version VersionInfo
avTools)
              , lNoBindist :: Bool
lNoBindist = Bool
False
              , fromSrc :: Bool
fromSrc    = Bool
False -- actually, we don't know :>
              , hlsPowered :: Bool
hlsPowered = Bool
False
              , lReleaseDay :: Maybe Day
lReleaseDay = forall (a :: OpticKind). Maybe a
Nothing
              , Bool
lSet :: Bool
lSet :: Bool
..
              }
      Left String
e -> do
        forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m,
 LabelOptic' "loggerConfig" A_Lens env LoggerConfig, MonadIO m) =>
Text -> m ()
logWarn
          forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Text
"Could not parse version of stray directory" forall (a :: OpticKind). Semigroup a => a -> a -> a
<> String -> Text
T.pack String
e
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure forall (a :: OpticKind). Maybe a
Nothing

  currentGHCup :: Map.Map GHCTargetVersion VersionInfo -> Maybe ListResult
  currentGHCup :: Map GHCTargetVersion VersionInfo -> Maybe ListResult
currentGHCup Map GHCTargetVersion VersionInfo
av =
    let currentVer :: GHCTargetVersion
currentVer = Version -> GHCTargetVersion
mkTVer forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (a :: OpticKind). HasCallStack => Maybe a -> a
fromJust forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (m :: OpticKind -> OpticKind).
MonadThrow m =>
PVP -> Text -> m Version
pvpToVersion PVP
ghcUpVer Text
""
        listVer :: Maybe VersionInfo
listVer    = forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Maybe a
Map.lookup GHCTargetVersion
currentVer Map GHCTargetVersion VersionInfo
av
        latestVer :: Maybe GHCTargetVersion
latestVer  = forall (a :: OpticKind) (b :: OpticKind). (a, b) -> a
fst forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (a :: OpticKind).
Is k A_Fold =>
Optic' k is s a -> s -> Maybe a
headOf (Tag
-> Fold
     (Map GHCTargetVersion VersionInfo) (GHCTargetVersion, VersionInfo)
getTagged Tag
Latest) Map GHCTargetVersion VersionInfo
av
        recommendedVer :: Maybe GHCTargetVersion
recommendedVer = forall (a :: OpticKind) (b :: OpticKind). (a, b) -> a
fst forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (a :: OpticKind).
Is k A_Fold =>
Optic' k is s a -> s -> Maybe a
headOf (Tag
-> Fold
     (Map GHCTargetVersion VersionInfo) (GHCTargetVersion, VersionInfo)
getTagged Tag
Latest) Map GHCTargetVersion VersionInfo
av
        isOld :: Bool
isOld  = forall (b :: OpticKind) (a :: OpticKind).
b -> (a -> b) -> Maybe a -> b
maybe Bool
True (forall (a :: OpticKind). Ord a => a -> a -> Bool
> GHCTargetVersion
currentVer) Maybe GHCTargetVersion
latestVer Bool -> Bool -> Bool
&& forall (b :: OpticKind) (a :: OpticKind).
b -> (a -> b) -> Maybe a -> b
maybe Bool
True (forall (a :: OpticKind). Ord a => a -> a -> Bool
> GHCTargetVersion
currentVer) Maybe GHCTargetVersion
recommendedVer
    in if | forall (k :: OpticKind) (a :: OpticKind).
Ord k =>
k -> Map k a -> Bool
Map.member GHCTargetVersion
currentVer Map GHCTargetVersion VersionInfo
av -> forall (a :: OpticKind). Maybe a
Nothing
          | Bool
otherwise -> forall (a :: OpticKind). a -> Maybe a
Just forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ListResult { lVer :: Version
lVer    = GHCTargetVersion -> Version
_tvVersion GHCTargetVersion
currentVer
                                           , lTag :: [Tag]
lTag    = forall (b :: OpticKind) (a :: OpticKind).
b -> (a -> b) -> Maybe a -> b
maybe (if Bool
isOld then [Tag
Old] else []) VersionInfo -> [Tag]
_viTags Maybe VersionInfo
listVer
                                           , lCross :: Maybe Text
lCross  = forall (a :: OpticKind). Maybe a
Nothing
                                           , lTool :: Tool
lTool   = Tool
GHCup
                                           , fromSrc :: Bool
fromSrc = Bool
False
                                           , lStray :: Bool
lStray  = forall (a :: OpticKind). Maybe a -> Bool
isNothing Maybe VersionInfo
listVer
                                           , lSet :: Bool
lSet    = Bool
True
                                           , lInstalled :: Bool
lInstalled = Bool
True
                                           , lNoBindist :: Bool
lNoBindist = Bool
False
                                           , hlsPowered :: Bool
hlsPowered = Bool
False
                                           , lReleaseDay :: Maybe Day
lReleaseDay = forall (a :: OpticKind). Maybe a
Nothing
                                           }

  -- NOTE: this are not cross ones, because no bindists
  toListResult :: ( HasLog env
                  , MonadReader env m
                  , HasDirs env
                  , HasGHCupInfo env
                  , HasPlatformReq env
                  , MonadIO m
                  , MonadCatch m
                  )
               => Tool
               -> Maybe Version
               -> [Either FilePath Version]
               -> Maybe Version
               -> [Either FilePath Version]
               -> Maybe Version
               -> [Either FilePath Version]
               -> (GHCTargetVersion, VersionInfo)
               -> m ListResult
  toListResult :: forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(HasLog env, MonadReader env m, HasDirs env, HasGHCupInfo env,
 HasPlatformReq env, MonadIO m, MonadCatch m) =>
Tool
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> Maybe Version
-> [Either String Version]
-> (GHCTargetVersion, VersionInfo)
-> m ListResult
toListResult Tool
t Maybe Version
cSet [Either String Version]
cabals Maybe Version
hlsSet' [Either String Version]
hlses Maybe Version
stackSet' [Either String Version]
stacks (GHCTargetVersion
tver, VersionInfo{[Tag]
Maybe Text
Maybe Day
Maybe URI
Maybe DownloadInfo
ArchitectureSpec
$sel:_viPreCompile:VersionInfo :: VersionInfo -> Maybe Text
$sel:_viPostRemove:VersionInfo :: VersionInfo -> Maybe Text
$sel:_viPostInstall:VersionInfo :: VersionInfo -> Maybe Text
$sel:_viArch:VersionInfo :: VersionInfo -> ArchitectureSpec
$sel:_viTestDL:VersionInfo :: VersionInfo -> Maybe DownloadInfo
$sel:_viSourceDL:VersionInfo :: VersionInfo -> Maybe DownloadInfo
$sel:_viChangeLog:VersionInfo :: VersionInfo -> Maybe URI
$sel:_viReleaseDay:VersionInfo :: VersionInfo -> Maybe Day
_viPreCompile :: Maybe Text
_viPostRemove :: Maybe Text
_viPostInstall :: Maybe Text
_viArch :: ArchitectureSpec
_viTestDL :: Maybe DownloadInfo
_viSourceDL :: Maybe DownloadInfo
_viChangeLog :: Maybe URI
_viReleaseDay :: Maybe Day
_viTags :: [Tag]
$sel:_viTags:VersionInfo :: VersionInfo -> [Tag]
..}) = do
    let v :: Version
v = GHCTargetVersion -> Version
_tvVersion GHCTargetVersion
tver
    case Tool
t of
      Tool
GHC -> do
        Bool
lNoBindist <- forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap (forall (a :: OpticKind) (b :: OpticKind). Either a b -> Bool
isLeft forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (es :: IxList) (a :: OpticKind).
VEither es a -> Either (V es) a
veitherToEither) forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (es :: IxList) (a :: OpticKind)
       (m :: OpticKind -> OpticKind).
Excepts es m a -> m (VEither es a)
runE @'[NoDownload] forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasPlatformReq env, HasGHCupInfo env) =>
Tool
-> GHCTargetVersion -> Excepts (NoDownload : NoIx) m DownloadInfo
getDownloadInfo' Tool
GHC GHCTargetVersion
tver
        Bool
lSet       <- forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap (forall (a :: OpticKind). Eq a => a -> a -> Bool
== forall (a :: OpticKind). a -> Maybe a
Just GHCTargetVersion
tver) forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadThrow m, MonadIO m) =>
Maybe Text -> m (Maybe GHCTargetVersion)
ghcSet (GHCTargetVersion -> Maybe Text
_tvTarget GHCTargetVersion
tver)
        Bool
lInstalled <- forall (m :: OpticKind -> OpticKind) (env :: OpticKind).
(MonadIO m, MonadReader env m, HasDirs env, MonadThrow m) =>
GHCTargetVersion -> m Bool
ghcInstalled GHCTargetVersion
tver
        Bool
fromSrc    <- forall (m :: OpticKind -> OpticKind) (env :: OpticKind).
(MonadIO m, MonadReader env m, HasDirs env, MonadThrow m) =>
GHCTargetVersion -> m Bool
ghcSrcInstalled GHCTargetVersion
tver
        Bool
hlsPowered <- forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap (forall (t :: OpticKind -> OpticKind) (a :: OpticKind).
(Foldable t, Eq a) =>
a -> t a -> Bool
elem GHCTargetVersion
tver) (forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap Version -> GHCTargetVersion
mkTVer forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasDirs env, MonadIO m, MonadThrow m,
 MonadCatch m) =>
m [Version]
hlsGHCVersions)
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ListResult { lVer :: Version
lVer = GHCTargetVersion -> Version
_tvVersion GHCTargetVersion
tver , lCross :: Maybe Text
lCross = GHCTargetVersion -> Maybe Text
_tvTarget GHCTargetVersion
tver , lTag :: [Tag]
lTag = [Tag]
_viTags, lTool :: Tool
lTool = Tool
t, lStray :: Bool
lStray = Bool
False, lReleaseDay :: Maybe Day
lReleaseDay = Maybe Day
_viReleaseDay, Bool
hlsPowered :: Bool
fromSrc :: Bool
lInstalled :: Bool
lSet :: Bool
lNoBindist :: Bool
hlsPowered :: Bool
lNoBindist :: Bool
fromSrc :: Bool
lSet :: Bool
lInstalled :: Bool
.. }
      Tool
Cabal -> do
        Bool
lNoBindist <- forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap (forall (a :: OpticKind) (b :: OpticKind). Either a b -> Bool
isLeft forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (es :: IxList) (a :: OpticKind).
VEither es a -> Either (V es) a
veitherToEither) forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (es :: IxList) (a :: OpticKind)
       (m :: OpticKind -> OpticKind).
Excepts es m a -> m (VEither es a)
runE @'[NoDownload] forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasPlatformReq env, HasGHCupInfo env) =>
Tool -> Version -> Excepts (NoDownload : NoIx) m DownloadInfo
getDownloadInfo Tool
Cabal Version
v
        let lSet :: Bool
lSet = Maybe Version
cSet forall (a :: OpticKind). Eq a => a -> a -> Bool
== forall (a :: OpticKind). a -> Maybe a
Just Version
v
        let lInstalled :: Bool
lInstalled = forall (t :: OpticKind -> OpticKind) (a :: OpticKind).
(Foldable t, Eq a) =>
a -> t a -> Bool
elem Version
v forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (a :: OpticKind) (b :: OpticKind). [Either a b] -> [b]
rights [Either String Version]
cabals
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ListResult { lVer :: Version
lVer    = Version
v
                        , lCross :: Maybe Text
lCross  = forall (a :: OpticKind). Maybe a
Nothing
                        , lTag :: [Tag]
lTag    = [Tag]
_viTags
                        , lTool :: Tool
lTool   = Tool
t
                        , fromSrc :: Bool
fromSrc = Bool
False
                        , lStray :: Bool
lStray  = Bool
False
                        , hlsPowered :: Bool
hlsPowered = Bool
False
                        , lReleaseDay :: Maybe Day
lReleaseDay = Maybe Day
_viReleaseDay
                        , Bool
lInstalled :: Bool
lSet :: Bool
lNoBindist :: Bool
lNoBindist :: Bool
lSet :: Bool
lInstalled :: Bool
..
                        }
      Tool
GHCup -> do
        let lSet :: Bool
lSet       = PVP -> Text
prettyPVP PVP
ghcUpVer forall (a :: OpticKind). Eq a => a -> a -> Bool
== Version -> Text
prettyVer Version
v
        let lInstalled :: Bool
lInstalled = Bool
lSet
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ListResult { lVer :: Version
lVer    = Version
v
                        , lTag :: [Tag]
lTag    = [Tag]
_viTags
                        , lCross :: Maybe Text
lCross  = forall (a :: OpticKind). Maybe a
Nothing
                        , lTool :: Tool
lTool   = Tool
t
                        , fromSrc :: Bool
fromSrc = Bool
False
                        , lStray :: Bool
lStray  = Bool
False
                        , lNoBindist :: Bool
lNoBindist = Bool
False
                        , hlsPowered :: Bool
hlsPowered = Bool
False
                        , lReleaseDay :: Maybe Day
lReleaseDay = Maybe Day
_viReleaseDay
                        , Bool
lInstalled :: Bool
lSet :: Bool
lSet :: Bool
lInstalled :: Bool
..
                        }
      Tool
HLS -> do
        Bool
lNoBindist <- forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap (forall (a :: OpticKind) (b :: OpticKind). Either a b -> Bool
isLeft forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (es :: IxList) (a :: OpticKind).
VEither es a -> Either (V es) a
veitherToEither) forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (es :: IxList) (a :: OpticKind)
       (m :: OpticKind -> OpticKind).
Excepts es m a -> m (VEither es a)
runE @'[NoDownload] forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasPlatformReq env, HasGHCupInfo env) =>
Tool -> Version -> Excepts (NoDownload : NoIx) m DownloadInfo
getDownloadInfo Tool
HLS Version
v
        let lSet :: Bool
lSet = Maybe Version
hlsSet' forall (a :: OpticKind). Eq a => a -> a -> Bool
== forall (a :: OpticKind). a -> Maybe a
Just Version
v
        let lInstalled :: Bool
lInstalled = forall (t :: OpticKind -> OpticKind) (a :: OpticKind).
(Foldable t, Eq a) =>
a -> t a -> Bool
elem Version
v forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (a :: OpticKind) (b :: OpticKind). [Either a b] -> [b]
rights [Either String Version]
hlses
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ListResult { lVer :: Version
lVer    = Version
v
                        , lCross :: Maybe Text
lCross  = forall (a :: OpticKind). Maybe a
Nothing
                        , lTag :: [Tag]
lTag    = [Tag]
_viTags
                        , lTool :: Tool
lTool   = Tool
t
                        , fromSrc :: Bool
fromSrc = Bool
False
                        , lStray :: Bool
lStray  = Bool
False
                        , hlsPowered :: Bool
hlsPowered = Bool
False
                        , lReleaseDay :: Maybe Day
lReleaseDay = Maybe Day
_viReleaseDay
                        , Bool
lInstalled :: Bool
lSet :: Bool
lNoBindist :: Bool
lNoBindist :: Bool
lSet :: Bool
lInstalled :: Bool
..
                        }
      Tool
Stack -> do
        Bool
lNoBindist <- forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap (forall (a :: OpticKind) (b :: OpticKind). Either a b -> Bool
isLeft forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (es :: IxList) (a :: OpticKind).
VEither es a -> Either (V es) a
veitherToEither) forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (es :: IxList) (a :: OpticKind)
       (m :: OpticKind -> OpticKind).
Excepts es m a -> m (VEither es a)
runE @'[NoDownload] forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (env :: OpticKind) (m :: OpticKind -> OpticKind).
(MonadReader env m, HasPlatformReq env, HasGHCupInfo env) =>
Tool -> Version -> Excepts (NoDownload : NoIx) m DownloadInfo
getDownloadInfo Tool
Stack Version
v
        let lSet :: Bool
lSet = Maybe Version
stackSet' forall (a :: OpticKind). Eq a => a -> a -> Bool
== forall (a :: OpticKind). a -> Maybe a
Just Version
v
        let lInstalled :: Bool
lInstalled = forall (t :: OpticKind -> OpticKind) (a :: OpticKind).
(Foldable t, Eq a) =>
a -> t a -> Bool
elem Version
v forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (a :: OpticKind) (b :: OpticKind). [Either a b] -> [b]
rights [Either String Version]
stacks
        forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ListResult { lVer :: Version
lVer    = Version
v
                        , lCross :: Maybe Text
lCross  = forall (a :: OpticKind). Maybe a
Nothing
                        , lTag :: [Tag]
lTag    = [Tag]
_viTags
                        , lTool :: Tool
lTool   = Tool
t
                        , fromSrc :: Bool
fromSrc = Bool
False
                        , lStray :: Bool
lStray  = Bool
False
                        , hlsPowered :: Bool
hlsPowered = Bool
False
                        , lReleaseDay :: Maybe Day
lReleaseDay = Maybe Day
_viReleaseDay
                        , Bool
lInstalled :: Bool
lSet :: Bool
lNoBindist :: Bool
lNoBindist :: Bool
lSet :: Bool
lInstalled :: Bool
..
                        }


  filter' :: [ListResult] -> [ListResult]
  filter' :: [ListResult] -> [ListResult]
filter' = [ListResult] -> [ListResult]
filterNightly forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. [ListResult] -> [ListResult]
filterOld forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (a :: OpticKind). (a -> Bool) -> [a] -> [a]
filter (\ListResult
lr -> forall (t :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\ListCriteria
a Bool
b -> ListCriteria -> ListResult -> Bool
fromCriteria ListCriteria
a ListResult
lr Bool -> Bool -> Bool
&& Bool
b) Bool
True [ListCriteria]
criteria) forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. [ListResult] -> [ListResult]
filterDays

  filterDays :: [ListResult] -> [ListResult]
  filterDays :: [ListResult] -> [ListResult]
filterDays [ListResult]
lrs = case (Maybe Day, Maybe Day)
days of
                     (Maybe Day
Nothing, Maybe Day
Nothing)    -> [ListResult]
lrs
                     (Just Day
from, Just Day
to') -> forall (a :: OpticKind). (a -> Bool) -> [a] -> [a]
filter (\ListResult{Bool
[Tag]
Maybe Text
Maybe Day
Version
Tool
lReleaseDay :: Maybe Day
hlsPowered :: Bool
lNoBindist :: Bool
lStray :: Bool
fromSrc :: Bool
lSet :: Bool
lInstalled :: Bool
lTag :: [Tag]
lCross :: Maybe Text
lVer :: Version
lTool :: Tool
lReleaseDay :: ListResult -> Maybe Day
hlsPowered :: ListResult -> Bool
lNoBindist :: ListResult -> Bool
lStray :: ListResult -> Bool
fromSrc :: ListResult -> Bool
lSet :: ListResult -> Bool
lInstalled :: ListResult -> Bool
lTag :: ListResult -> [Tag]
lCross :: ListResult -> Maybe Text
lVer :: ListResult -> Version
lTool :: ListResult -> Tool
..} -> forall (b :: OpticKind) (a :: OpticKind).
b -> (a -> b) -> Maybe a -> b
maybe Bool
False (\Day
d -> Day
d forall (a :: OpticKind). Ord a => a -> a -> Bool
>= Day
from Bool -> Bool -> Bool
&& Day
d forall (a :: OpticKind). Ord a => a -> a -> Bool
<= Day
to') Maybe Day
lReleaseDay) [ListResult]
lrs
                     (Maybe Day
Nothing, Just Day
to')   -> forall (a :: OpticKind). (a -> Bool) -> [a] -> [a]
filter (\ListResult{Bool
[Tag]
Maybe Text
Maybe Day
Version
Tool
lReleaseDay :: Maybe Day
hlsPowered :: Bool
lNoBindist :: Bool
lStray :: Bool
fromSrc :: Bool
lSet :: Bool
lInstalled :: Bool
lTag :: [Tag]
lCross :: Maybe Text
lVer :: Version
lTool :: Tool
lReleaseDay :: ListResult -> Maybe Day
hlsPowered :: ListResult -> Bool
lNoBindist :: ListResult -> Bool
lStray :: ListResult -> Bool
fromSrc :: ListResult -> Bool
lSet :: ListResult -> Bool
lInstalled :: ListResult -> Bool
lTag :: ListResult -> [Tag]
lCross :: ListResult -> Maybe Text
lVer :: ListResult -> Version
lTool :: ListResult -> Tool
..} -> forall (b :: OpticKind) (a :: OpticKind).
b -> (a -> b) -> Maybe a -> b
maybe Bool
False (forall (a :: OpticKind). Ord a => a -> a -> Bool
<= Day
to')                      Maybe Day
lReleaseDay) [ListResult]
lrs
                     (Just Day
from, Maybe Day
Nothing)  -> forall (a :: OpticKind). (a -> Bool) -> [a] -> [a]
filter (\ListResult{Bool
[Tag]
Maybe Text
Maybe Day
Version
Tool
lReleaseDay :: Maybe Day
hlsPowered :: Bool
lNoBindist :: Bool
lStray :: Bool
fromSrc :: Bool
lSet :: Bool
lInstalled :: Bool
lTag :: [Tag]
lCross :: Maybe Text
lVer :: Version
lTool :: Tool
lReleaseDay :: ListResult -> Maybe Day
hlsPowered :: ListResult -> Bool
lNoBindist :: ListResult -> Bool
lStray :: ListResult -> Bool
fromSrc :: ListResult -> Bool
lSet :: ListResult -> Bool
lInstalled :: ListResult -> Bool
lTag :: ListResult -> [Tag]
lCross :: ListResult -> Maybe Text
lVer :: ListResult -> Version
lTool :: ListResult -> Tool
..} -> forall (b :: OpticKind) (a :: OpticKind).
b -> (a -> b) -> Maybe a -> b
maybe Bool
False (forall (a :: OpticKind). Ord a => a -> a -> Bool
>= Day
from)                     Maybe Day
lReleaseDay) [ListResult]
lrs

  fromCriteria :: ListCriteria -> ListResult -> Bool
  fromCriteria :: ListCriteria -> ListResult -> Bool
fromCriteria ListCriteria
lc ListResult{Bool
[Tag]
Maybe Text
Maybe Day
Version
Tool
lReleaseDay :: Maybe Day
hlsPowered :: Bool
lNoBindist :: Bool
lStray :: Bool
fromSrc :: Bool
lSet :: Bool
lInstalled :: Bool
lTag :: [Tag]
lCross :: Maybe Text
lVer :: Version
lTool :: Tool
lReleaseDay :: ListResult -> Maybe Day
hlsPowered :: ListResult -> Bool
lNoBindist :: ListResult -> Bool
lStray :: ListResult -> Bool
fromSrc :: ListResult -> Bool
lSet :: ListResult -> Bool
lInstalled :: ListResult -> Bool
lTag :: ListResult -> [Tag]
lCross :: ListResult -> Maybe Text
lVer :: ListResult -> Version
lTool :: ListResult -> Tool
..} = case ListCriteria
lc of
    ListInstalled  Bool
b -> Bool -> Bool -> Bool
f Bool
b Bool
lInstalled
    ListSet        Bool
b -> Bool -> Bool -> Bool
f Bool
b Bool
lSet
    ListAvailable  Bool
b -> Bool -> Bool -> Bool
f Bool
b forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
lNoBindist
   where
    f :: Bool -> Bool -> Bool
f Bool
b
      | Bool
b         = forall (a :: OpticKind). a -> a
id
      | Bool
otherwise = Bool -> Bool
not

  filterOld :: [ListResult] -> [ListResult]
  filterOld :: [ListResult] -> [ListResult]
filterOld [ListResult]
lr
    | Bool
hideOld   = forall (a :: OpticKind). (a -> Bool) -> [a] -> [a]
filter (\ListResult {Bool
[Tag]
Maybe Text
Maybe Day
Version
Tool
lReleaseDay :: Maybe Day
hlsPowered :: Bool
lNoBindist :: Bool
lStray :: Bool
fromSrc :: Bool
lSet :: Bool
lInstalled :: Bool
lTag :: [Tag]
lCross :: Maybe Text
lVer :: Version
lTool :: Tool
lReleaseDay :: ListResult -> Maybe Day
hlsPowered :: ListResult -> Bool
lNoBindist :: ListResult -> Bool
lStray :: ListResult -> Bool
fromSrc :: ListResult -> Bool
lSet :: ListResult -> Bool
lInstalled :: ListResult -> Bool
lTag :: ListResult -> [Tag]
lCross :: ListResult -> Maybe Text
lVer :: ListResult -> Version
lTool :: ListResult -> Tool
..} -> Bool
lInstalled Bool -> Bool -> Bool
|| Tag
Old forall (t :: OpticKind -> OpticKind) (a :: OpticKind).
(Foldable t, Eq a) =>
a -> t a -> Bool
`notElem` [Tag]
lTag) [ListResult]
lr
    | Bool
otherwise = [ListResult]
lr

  filterNightly :: [ListResult] -> [ListResult]
  filterNightly :: [ListResult] -> [ListResult]
filterNightly [ListResult]
lr
    | Bool
showNightly = [ListResult]
lr
    | Bool
otherwise   = forall (a :: OpticKind). (a -> Bool) -> [a] -> [a]
filter (\ListResult {Bool
[Tag]
Maybe Text
Maybe Day
Version
Tool
lReleaseDay :: Maybe Day
hlsPowered :: Bool
lNoBindist :: Bool
lStray :: Bool
fromSrc :: Bool
lSet :: Bool
lInstalled :: Bool
lTag :: [Tag]
lCross :: Maybe Text
lVer :: Version
lTool :: Tool
lReleaseDay :: ListResult -> Maybe Day
hlsPowered :: ListResult -> Bool
lNoBindist :: ListResult -> Bool
lStray :: ListResult -> Bool
fromSrc :: ListResult -> Bool
lSet :: ListResult -> Bool
lInstalled :: ListResult -> Bool
lTag :: ListResult -> [Tag]
lCross :: ListResult -> Maybe Text
lVer :: ListResult -> Version
lTool :: ListResult -> Tool
..} -> Bool
lInstalled Bool -> Bool -> Bool
|| (Tag
Nightly forall (t :: OpticKind -> OpticKind) (a :: OpticKind).
(Foldable t, Eq a) =>
a -> t a -> Bool
`notElem` [Tag]
lTag Bool -> Bool -> Bool
&& Tag
LatestNightly forall (t :: OpticKind -> OpticKind) (a :: OpticKind).
(Foldable t, Eq a) =>
a -> t a -> Bool
`notElem` [Tag]
lTag)) [ListResult]
lr