Skip to content

Instantly share code, notes, and snippets.

@fujimura
Created November 12, 2013 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fujimura/7431024 to your computer and use it in GitHub Desktop.
Save fujimura/7431024 to your computer and use it in GitHub Desktop.
Read `.cabal` and pretty print it
import Distribution.PackageDescription.Parse (readPackageDescription)
import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription)
import Distribution.Verbosity (silent)
-- Taken from http://therning.org/magnus/archives/514. Thanks @magthe
main = do
gpd <- readPackageDescription silent "hi.cabal"
putStrLn $ showGenericPackageDescription gpd
@fujimura
Copy link
Author

$ runhaskell cabal.hs
name: hi
version: 0.0.6
cabal-version: >=1.8
build-type: Simple
license: BSD3
license-file: LICENSE
maintainer: me@fujimuradaisuke.com
homepage: https://github.com/fujimura/hi
synopsis: Generate scaffold for cabal project
description: This application generates a scaffold for Haskell project from a Git repository.
             .
             This command
             .
             .
             > $ hi --package-name "foo-bar-baz" --module-name "Foo.Bar.Baz" --author "Fujimura Daisuke" --email "me@fujimuradaisuke.com"
             .
             .
             will generate:
             .
             .
             > $ tree .
             > .
             > ├── LICENSE
             > ├── README.md
             > ├── foo-bar-baz.cabal
             > ├── src
             > │  └── Foo
             > │      └── Bar
             > │          ├── Baz
             > │          │  └── Internal.hs
             > │          └── Baz.hs
             > └── test
             >     ├── Foo
             >     │  └── Bar
             >     │      ├── Baz
             >     │      └── BazSpec.hs
             >     └── Spec.hs
             .
             .
             See <https://github.com/fujimura/hi> for further usage.
             .
category: Distribution
author: Fujimura Daisuke
data-dir: ""

source-repository head
    type: git
    location: https://github.com/fujimura/hi.git

library
    build-depends: base ==4.*, bytestring -any, directory -any,
                   filepath -any, parsec -any, process -any, split -any,
                   template ==0.2.*, temporary -any, text -any, time -any
    exposed-modules: Hi Hi.Config Hi.Directory Hi.FilePath Hi.Flag
                     Hi.Option Hi.Template Hi.Types Hi.Version
    exposed: True
    buildable: True
    hs-source-dirs: src
    ghc-options: -Wall

executable hi
    build-depends: base ==4.*, bytestring -any, directory -any,
                   filepath -any, parsec -any, process -any, split -any,
                   template ==0.2.*, temporary -any, text -any, time -any
    main-is: Main.hs
    buildable: True
    hs-source-dirs: src
    ghc-options: -Wall

test-suite spec
    build-depends: base -any, HUnit -any, bytestring -any,
                   directory -any, filepath -any, hspec >=1.7.2, parsec -any,
                   process -any, split -any, template ==0.2.*, temporary -any,
                   text -any, time -any
    type: exitcode-stdio-1.0
    main-is: Spec.hs
    buildable: True
    hs-source-dirs: src test
    ghc-options: -Wall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment