Clinton
Clinton

Reputation: 23135

Getting a list of `PackageDescriptions` from the local database

Is there anyway, presumably using the Cabal package, to get a list of PackageDesciptions in the current local database?

Upvotes: 0

Views: 26

Answers (1)

epsilonhalbe
epsilonhalbe

Reputation: 15959

I don't know if there's a "built-in"-way of doing this, but I've used this

ghc-pkg list | grep -v "\(^/\|^$\|(\)" | xargs cabal info | grep "\(^\*\|License\)"

to extract "License" info for all installed packages.

  1. If you use stack or cabal-sandbox - the first command needs to be replaced by either stack exec -- ghc-pkg list or cabal sandbox hc-pkg list.
  2. the (first) regex removes the path-lines like /opt/ghc/8.0.2/lib/ghc-8.0.2/package.conf.d, empty lines and lines starting with ( - somehow the colored lines produced by ghc-pkg like ghc-8.0.2 end up with starting ( in my terminal when grepping.
  3. "map cabal info over all packages"
  4. [optional] extracting the package information for the package itself (starting with * and the License field.

I hope this is what you were looking for. Another way, I think, would be writing a haskell program and use Cabal as a library.

Upvotes: 2

Related Questions