Commit a682875c authored by Wojciech Danilo's avatar Wojciech Danilo
Browse files

Refactoring: extracting 'List.getPkgList' function out of 'List.list'...

Refactoring: extracting 'List.getPkgList' function out of 'List.list' function. The 'getPkgList' function returns list of packages and be used by external programs, when cabal-install becomes a library.
parent a49801ef
......@@ -70,17 +70,16 @@ import System.Directory
( doesDirectoryExist )
-- |Show information about packages
list :: Verbosity
-> PackageDBStack
-> [Repo]
-> Compiler
-> ProgramConfiguration
-> ListFlags
-> [String]
-> IO ()
list verbosity packageDBs repos comp conf listFlags pats = do
-- |Returns list of packages matching a search strings
getPkgList :: Verbosity
-> PackageDBStack
-> [Repo]
-> Compiler
-> ProgramConfiguration
-> ListFlags
-> [String]
-> IO [PackageDisplayInfo]
getPkgList verbosity packageDBs repos comp conf listFlags pats = do
installedPkgIndex <- getInstalledPackages verbosity comp packageDBs conf
sourcePkgDb <- getSourcePackages verbosity repos
let sourcePkgIndex = packageIndex sourcePkgDb
......@@ -104,6 +103,26 @@ list verbosity packageDBs repos comp conf listFlags pats = do
, not onlyInstalled || not (null installedPkgs)
, let pref = prefs pkgname
selectedPkg = latestWithPref pref sourcePkgs ]
return matches
where
onlyInstalled = fromFlag (listInstalled listFlags)
matchingPackages search index =
[ pkg
| pat <- pats
, pkg <- search index pat ]
-- |Show information about packages
list :: Verbosity
-> PackageDBStack
-> [Repo]
-> Compiler
-> ProgramConfiguration
-> ListFlags
-> [String]
-> IO ()
list verbosity packageDBs repos comp conf listFlags pats = do
matches <- getPkgList verbosity packageDBs repos comp conf listFlags pats
if simpleOutput
then putStr $ unlines
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment