Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Fredrik Wieczerkowski
curry-tools
Commits
b84a2729
Commit
b84a2729
authored
Apr 12, 2017
by
Michael Hanus
Browse files
CPM updated
parent
911a8429
Changes
3
Hide whitespace changes
Inline
Side-by-side
cpm/docs/manual.tex
View file @
b84a2729
...
...
@@ -579,7 +579,7 @@ Prints basic information on the given package version.
The option
\code
{
--all
}
shows more information.
\item
[\fbox{\code{list [--all]
[--csv]
}}
] List the names and synopses of all
packages of the central package index.
packages
(compatible to the current compiler)
of the central package index.
The option
\code
{
--all
}
shows also all package versions.
The option
\code
{
--csv
}
shows the information in CSV format.
...
...
@@ -590,7 +590,8 @@ of the central package index.
The option
\code
{
--csv
}
shows the information in CSV format.
\item
[\fbox{\code{search $query$}}]
Searches the names and synopses of all
packages in the central package index for a term.
packages (compatible to the current compiler)
of the central package index for a term.
\item
[\fbox{\code{update}}]
Updates the local copy of the central package index
to the newest available version.
...
...
cpm/src/CPM/Main.curry
View file @
b84a2729
...
...
@@ -684,60 +684,73 @@ tryFindVersion pkg ver repo = case findVersion repo pkg ver of
"' not found in package repository."
Just p -> succeedIO $ p
--- Lists all packages in the given repository.
--- Lists all
(compiler-compatible)
packages in the given repository.
listCmd :: ListOptions -> Config -> Repository -> IO (ErrorLogger ())
listCmd (ListOptions lv csv cat)
_
repo =
listCmd (ListOptions lv csv cat)
cfg
repo =
if cat then putStr (renderCats catgroups) >> succeedIO ()
else putStr (renderPkgs allpkgs) >> succeedIO ()
where
-- all packages (and versions if `lv`)
allpkgs = concatMap (if lv then id else ((:[]) . head))
(sortBy (\ps1 ps2 -> name (head ps1) <= name (head ps2))
(listPackages repo))
(listPackages
cfg
repo))
-- all categories together with their package names:
catgroups =
let newpkgs = map head (listPackages repo)
catpkgs = concatMap (\p -> map (\c -> (c, name p)) (category p)) newpkgs
nocatps = map name (filter (null . category) newpkgs)
let pkgid p = name p ++ '-' : showVersion (version p)
newpkgs = map head (listPackages cfg repo)
catpkgs = concatMap (\p -> map (\c -> (c, pkgid p)) (category p))
newpkgs
nocatps = map pkgid (filter (null . category) newpkgs)
in map (\cg -> (fst (head cg), map snd cg))
(groupBy (\ (c1,_) (c2,_) -> c1==c2) (nub $ sortBy (<=) catpkgs)) ++
if null nocatps then []
else [("???", nub $ sortBy (<=) nocatps)]
renderPkgs pkgs =
let namelen = foldl max 4 $ map (length . name) pkgs
header = [ ["Name", "Synopsis", "Version"]
, ["----", "--------", "-------"]]
formatPkg p = [name p, synopsis p, showVersion (version p)]
columns = header ++ map formatPkg pkgs
in renderTable [namelen + 4, 66 - namelen, 10] columns
let (colsizes,rows) = packageVersionAsTable pkgs
in renderTable colsizes rows
renderCats catgrps =
let namelen = foldl max 8 $ map (length . fst) catgrps
header = [ ["Category", "Packages"]
, ["--------", "--------"]]
columns
= header ++ map (\ (c,ns) -> [c, unwords ns]) catgrps
in renderTable [namelen + 4, 76 - namelen]
column
s
rows
= header ++ map (\ (c,ns) -> [c, unwords ns]) catgrps
in renderTable [namelen + 4, 76 - namelen]
row
s
renderTable colsizes cols =
if csv then showCSV (head cols : drop 2 cols)
else render (table cols colsizes) ++ cpmInfo
renderTable colsizes rows =
if csv then showCSV (head rows : drop 2 rows)
else unlines [render (table rows colsizes), cpmInfo, cpmUpdate]
-- Format a list of packages by showing their names, synopsis, and versions
-- as table rows. Returns also the column sizes.
packageVersionAsTable :: [Package] -> ([Int],[[String]])
packageVersionAsTable pkgs = (colsizes, rows)
where
namelen = foldl max 4 $ map (length . name) pkgs
colsizes = [namelen + 4, 66 - namelen, 10]
header = [ ["Name", "Synopsis", "Version"]
, ["----", "--------", "-------"]]
rows = header ++ map formatPkg pkgs
formatPkg p = [name p, synopsis p, showVersion (version p)]
cpmInfo :: String
cpmInfo = "Use 'cpm info PACKAGE' for more information about a package."
cpm
Info = "\nUse 'cpm info PACKAGE' for more information about a package." ++
"\n
Use 'cpm update' to download the newest package index.
\n
"
cpm
Update :: String
cpmUpdate = "
Use 'cpm update' to download the newest package index."
--- Search in all (compiler-compatible) packages in the given repository.
search :: SearchOptions -> Config -> Repository -> IO (ErrorLogger ())
search (SearchOptions q)
_
repo = putStr rendered >> succeedIO ()
search (SearchOptions q)
cfg
repo = putStr rendered >> succeedIO ()
where
results = sortBy (\p1 p2 -> name p1 <= name p2) (searchPackages repo q)
rendered = if length results == 0
then "No packages found for '" ++ q ++ "'\n"
else render $ table columns [nameLen + 4, 76 - nameLen]
header = [["Name", "Synopsis"], ["----", "--------"], [" ", " "]]
columns = header ++ map (\p -> [name p, synopsis p]) results
nameLen = foldl max 0 $ map (length . name) results
results = sortBy (\p1 p2 -> name p1 <= name p2) (searchPackages cfg repo q)
(colsizes,rows) = packageVersionAsTable results
rendered = unlines $
if null results
then ["No packages found for '" ++ q, "", cpmUpdate]
else [ render (table rows colsizes), cpmInfo, cpmUpdate ]
upgrade :: UpgradeOptions -> Config -> Repository -> GlobalCache
-> IO (ErrorLogger ())
...
...
cpm/src/CPM/Repository.curry
View file @
b84a2729
...
...
@@ -53,31 +53,37 @@ findAllVersions (Repository ps) p pre =
sameName = filter ((== p) . name)
filterPre p' = pre || (not . isPreRelease . version) p'
--- Search the names and synopses of all packages in the repository for a
--- particular term. Lower/upercase is ignored for the search.
--- Search the names and synopses of all compiler-compatbile packages
--- in the repository for a particular term.
--- Lower/upercase is ignored for the search.
--- Returns the newest matching version of each package.
---
--- @param cfg - the current CPM configuration
--- @param repo - the repository
--- @param q - the term to search for
searchPackages :: Repository -> String -> [Package]
searchPackages (Repository ps) searchstring =
searchPackages ::
Config ->
Repository -> String -> [Package]
searchPackages
cfg
(Repository ps) searchstring =
map (head . sortedByVersion) groupedResults
where
groupedResults = groupBy namesEqual allResults
allResults = filter (matches (lowerS searchstring)) ps
allResults = filter (isCompatibleToCompiler cfg)
(filter (matches (lowerS searchstring)) ps)
matches q p = q `isInfixOf` (lowerS $ name p) ||
q `isInfixOf` (lowerS $ synopsis p)
namesEqual a b = (name a) == (name b)
sortedByVersion = sortBy (\a b -> (version a) `vgt` (version b))
lowerS = map toLower
--- Get all packages in the repository
and group them by versions
--- (newest first).
--- Get all packages in the repository
(which are compatible to the
---
current compiler) and group them by versions
(newest first).
---
--- @param cfg - the current CPM configuration
--- @param repo - the repository
listPackages :: Repository -> [[Package]]
listPackages (Repository ps) =
map sortedByVersion (groupBy (\a b -> name a == name b) ps)
listPackages :: Config -> Repository -> [[Package]]
listPackages cfg (Repository ps) =
map sortedByVersion
(groupBy (\a b -> name a == name b)
(filter (isCompatibleToCompiler cfg) ps))
where
sortedByVersion = sortBy (\a b -> (version a) `vgt` (version b))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment