hgrev

Compile Mercurial (hg) version info into Haskell code

https://github.com/bitnomial/hgrev

Version on this page:0.2.3
LTS Haskell 18.28:0.2.6
Stackage Nightly 2021-06-14:0.2.6
Latest on Hackage:0.2.6

See all snapshots hgrev appears in

BSD-3-Clause licensed by Luke Hoersten
Maintained by [email protected]
This version can be pinned in stack with:hgrev-0.2.3@sha256:2bbabb17eadc9e656f6c73863b6df472bf0db86da55b152e98542511955d84d4,2990

Module documentation for 0.2.3

HgRev

Compile Mercurial (hg) version info into Haskell code

Overview

hgrev provides two modules:

  • Development.HgRev - Mercurial (hg) Haskell API
  • Development.HgRev.TH - Template Haskell splice to compile version info into Haskell code

Use $(hgRevStateTH defFormat) with Template Haskell enabled to insert the formatted version string.

Requirements

hgrev requires the hg binary version 3.2 or greater is installed and available on the system. Development.HgRev.HgRev and Development.HgRev.HgState are obtained via two separate calls to hg because working directory state isn’t available programmatically.

Usage Example

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell   #-}

module Example where

import           Data.Monoid          ((<>))
import           Data.Text            (Text, pack)
import           Development.HgRev.TH (defFormat, hgRevStateTH, jsonFormat)
import           Options.Applicative  (Parser, ParserInfo, execParser, fullDesc,
                                        help, helper, info, infoOption, long,
                                        progDesc, short)

main :: IO ()
main = execParser parserInfo >> return ()

verSwitch :: Parser (a -> a)
verSwitch =
    infoOption ("HG rev: " <> $(hgRevStateTH defFormat))
    $  long "version"
    <> short 'v'
    <> help "Display version information"

jsonSwitch :: Parser (a -> a)
jsonSwitch =
    infoOption $(hgRevStateTH jsonFormat)
    $  long "json"
    <> short 'J'
    <> help "Display JSON version information"

parserInfo :: ParserInfo (a -> a)
parserInfo = info (helper <*> verSwitch <* jsonSwitch) fullDesc

Check out the gitrev package for similar git functionality.