Commit 8c38e5ab authored by bjorn@bringert.net's avatar bjorn@bringert.net
Browse files

cabal list now only shows one line per package, with a list of verions.

parent ecc95805
......@@ -16,13 +16,14 @@ module Hackage.List
import Text.Regex
import Data.Maybe (isJust)
import Data.List (nubBy, sortBy)
import Data.List (nubBy, sortBy, groupBy, intersperse)
import Data.Char as Char (toLower)
import Data.Ord (comparing)
import Distribution.Package
import Distribution.PackageDescription
import Distribution.Version (showVersion)
import Hackage.Config (getKnownPackages)
import Hackage.Types (PkgInfo(..), ConfigFlags(..), {- UnresolvedDependency(..)-} )
import Hackage.Types (PkgInfo(..), pkgInfoId, ConfigFlags(..), {- UnresolvedDependency(..)-} )
-- |Show information about packages
list :: ConfigFlags -> [String] -> IO ()
......@@ -30,7 +31,7 @@ list cfg pats = do
pkgs <- getKnownPackages cfg
let pkgs' | null pats = pkgs
| otherwise = nubBy samePackage (concatMap (findInPkgs pkgs) pats)
mapM_ doList (sortBy (comparing nameAndVersion) pkgs')
mapM_ doList (groupBy sameName (sortBy (comparing nameAndVersion) pkgs'))
where
findInPkgs :: [PkgInfo] -> String -> [PkgInfo]
findInPkgs pkgs pat = let rx = mkRegexWithOpts pat False False in
......@@ -43,12 +44,15 @@ list cfg pats = do
name = pkgName (package d)
version = pkgVersion (package d)
samePackage a b = nameAndVersion a == nameAndVersion b
sameName a b = pkgName (pkgInfoId a) == pkgName (pkgInfoId b)
doList :: PkgInfo -> IO ()
doList info = do
putStr . (if null syn then id else padTo 25) . showPackageId . package $ d
doList :: [PkgInfo] -> IO ()
doList ps = do
putStr $ padTo 35 $ pkgName (package d) ++ " [" ++ concat (intersperse "," versions) ++ "]"
putStrLn syn
where
info = last ps
d = packageDescription (pkgDesc info)
syn = synopsis d
versions = map (showVersion . pkgVersion . package . packageDescription . pkgDesc) ps
padTo n s = s ++ (replicate (n - length s) ' ')
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