tfausak / cabal-gild

:crown: Format Haskell package descriptions.
https://hackage.haskell.org/package/cabal-gild
MIT License
44 stars 4 forks source link
cabal formatter haskell

Gild

CI Hackage

Gild is an opinionated command line utility that formats Haskell package descriptions, which are also known as *.cabal files. Gild can also be used to automatically discover exposed-modules; see the pragmas section for more about that.

Gild started as a fork of phadej/cabal-fmt, but is now totally separate. For a brief summary of the differences between Gild and cabal-fmt, read [the announcement post][].

Summary

Given a package description like this:

CABAL-VERSION : 3.0
name          : example
version       : 0.0.0.0

library
  build-depends: mtl>=2.3, base
  ghc-options:-Wall
  if impl(ghc>=9.8)
    ghc-options: -Wmissing-role-annotations

Gild will produce output like this:

cabal-version: 3.0
name: example
version: 0.0.0.0

library
  build-depends:
    base,
    mtl >=2.3,

  ghc-options: -Wall

  if impl(ghc >= 9.8)
    ghc-options: -Wmissing-role-annotations

See the installation section for how to get Gild and the usage section for how to use it.

Goals

Installation

Go to the latest release page and download the binary for your platform.

To run Gild in a GitHub Actions workflow, consider using cabal-gild-setup-action.

From Source

In general you should prefer downloading the appropriate binary for you platform. However it is possible to build Gild from source. It supports Linux, macOS, and Windows along with the three most recent versions of GHC. Any other configurations are unsupported.

With Cabal:

$ cabal install cabal-gild

With Stack:

$ stack install cabal-gild

Usage

Gild is a command line utility named cabal-gild. By default it reads from standard input (STDIN) and writes to standard output (STDOUT). Its behavior can be modified with command line options, which are described below.

Options

Run cabal-gild --help to see the options that Gild supports. They are:

Pragmas

Gild supports special comments in package descriptions that act as pragmas. Each pragma starts with -- cabal-gild:. Pragmas must be the last comment before a field.

discover

-- cabal-gild: discover [DIRECTORY ...] [--include=PATTERN ...] [--exclude=PATTERN ...]

This pragma will discover files in any of the given directories. If no directories are given, defaults to . (the directory of the package description). For example, given this input:

library
  -- cabal-gild: discover
  exposed-modules: ...

Assuming there is a single Haskell file at Example.hs, Gild will produce this output:

library
  -- cabal-gild: discover
  exposed-modules: Example

This pragma works with the following fields:

It will be ignored on all other fields. For the exposed-modules, other-modules, and signatures fields, only files with the following extensions will be discovered:

For all other fields, files with any extension will be discovered.

Any existing files, modules, or signatures in the field will be ignored. The entire field will be replaced. This means adding, removing, and renaming files should be handled automatically.

Directories can be quoted if they contain spaces. For example:

library
  -- cabal-gild: discover "my modules"
  exposed-modules: ...

By default, all files in any of the given directories are considered for discovery. To explicitly include only certain files, use the --include=PATTERN option. For example:

library
  -- cabal-gild: discover --include=**/*Spec.hs
  other-modules: ...

Files can be excluded from discovery by using the --exclude=PATTERN option. For example:

library
  -- cabal-gild: discover --exclude=**/*Spec.hs
  exposed-modules: ...

If a file would match both the --include pattern and the --exclude pattern, it will be excluded.