- where maybe_hide p | pkgName (package p) == name = p {exposed=False}
- | otherwise = p
-
-
-matchingPackages :: String -> [PackageConfig]
- -> Maybe ([PackageConfig], [PackageConfig])
-matchingPackages str pkgs
- = case partition (matches str) pkgs of
- ([],_) -> Nothing
- (ps,rest) -> Just (sortByVersion ps, rest)
- where
- -- A package named on the command line can either include the
- -- version, or just the name if it is unambiguous.
- matches str p
- = str == showPackageId (package p)
- || str == pkgName (package p)
-
-
-pickPackages pkgs strs =
- [ p | p <- strs, Just (p:ps,_) <- [matchingPackages p pkgs] ]
-
-sortByVersion = sortBy (flip (comparing (pkgVersion.package)))
+ where maybe_hide p
+ | pkgName (sourcePackageId p) == name = p {exposed=False}
+ | otherwise = p
+
+
+selectPackages :: (PackageConfig -> Bool) -> [PackageConfig]
+ -> UnusablePackages
+ -> Either [(PackageConfig, UnusablePackageReason)]
+ ([PackageConfig], [PackageConfig])
+selectPackages matches pkgs unusable
+ = let
+ (ps,rest) = partition matches pkgs
+ reasons = [ (p, lookupFM unusable (installedPackageId p))
+ | p <- ps ]
+ in
+ if all (isJust.snd) reasons
+ then Left [ (p, reason) | (p,Just reason) <- reasons ]
+ else Right (sortByVersion [ p | (p,Nothing) <- reasons ], rest)
+
+-- A package named on the command line can either include the
+-- version, or just the name if it is unambiguous.
+matchingStr :: String -> PackageConfig -> Bool
+matchingStr str p
+ = str == display (sourcePackageId p)
+ || str == display (pkgName (sourcePackageId p))
+
+matchingId :: String -> PackageConfig -> Bool
+matchingId str p = InstalledPackageId str == installedPackageId p
+
+sortByVersion :: [InstalledPackageInfo_ m] -> [InstalledPackageInfo_ m]
+sortByVersion = sortBy (flip (comparing (pkgVersion.sourcePackageId)))
+
+comparing :: Ord a => (t -> a) -> t -> t -> Ordering