File: GetCabalVersion.hs

package info (click to toggle)
haskell-devscripts 0.16.34
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 272 kB
  • sloc: perl: 1,199; haskell: 30; sh: 19; makefile: 17
file content (28 lines) | stat: -rw-r--r-- 846 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE CPP #-}

import Distribution.PackageDescription (package, packageDescription)
#if __GLASGOW_HASKELL__ < 904
import Distribution.PackageDescription.Parsec (readGenericPackageDescription)
#else
import Distribution.Simple.PackageDescription (readGenericPackageDescription)
#endif
import Distribution.Pretty (prettyShow)
import Distribution.Types.PackageId (PackageIdentifier, pkgVersion)
import Distribution.Verbosity (silent)
import System.Environment (getArgs)

getPackageId :: IO PackageIdentifier
getPackageId = do
    args <- getArgs
    gpd <- readGenericPackageDescription silent (head args)
    return $ package $ packageDescription gpd

packageVersion :: PackageIdentifier -> String
packageVersion =
  prettyShow . pkgVersion

main :: IO ()
main = do
    pkgid <- getPackageId
    putStrLn $ packageVersion pkgid
    return ()