Skip to content

Commit

Permalink
[ new ] version command (with git hash)
Browse files Browse the repository at this point in the history
Note that the git hash will only be included if you compile the project
using `cabal v1-install` because `v2-install` uses a temporary directory
outside of the git project to do the build...

Cf. acfoltzer/gitrev#23
  • Loading branch information
gallais committed Apr 17, 2020
1 parent b3d604f commit a87b8db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions mary.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ library
, containers >=0.6 && <0.7
, directory >=1.3.3.0 && <1.3.3.4
, filepath >=1.4.2.1 && <1.4.3
, gitrev >=1.0 && <1.4
, hs-php-session >=0.0.9.3 && <0.0.10
, mtl >=2 && <3
, newtype >=0.2 && <0.3
Expand All @@ -81,6 +82,7 @@ library
, Mary.Pandoc
, Mary.ServePage
, Mary.Find
, Mary.Version
, Shonkier
, Shonkier.Examples
, Shonkier.FreeVars
Expand All @@ -99,6 +101,8 @@ library
, Shonkier.Value
, Utils.List

other-modules: Paths_mary

-- LANGUAGE extensions used by modules in this package.
-- other-extensions:

Expand Down
10 changes: 8 additions & 2 deletions mary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Data.List as L
import Data.Maybe
import Data.Semigroup ((<>))
import Data.Text
import Data.Text.IO as TIO
import qualified Data.Text.IO as TIO

import Text.Pandoc.JSON (toJSONFilter)

Expand All @@ -20,8 +20,9 @@ import Shonkier
import Mary.Pandoc
import Mary.ServePage
import Mary.Find
import Mary.Version

import Paths_mary
import Paths_mary (getDataFileName)

defaultUser :: IO String
defaultUser = do
Expand All @@ -31,6 +32,7 @@ defaultUser = do
main :: IO ()
main = customExecParser pp opts >>= \ o -> E.handle h $ case o of
Pandoc -> toJSONFilter process
Version -> putStrLn version
Shonkier filename -> interpretShonkier filename
Shonkierjs filename -> do
shonkierjs <- getDataFileName "src/data-dir/Shonkier.js"
Expand Down Expand Up @@ -58,6 +60,7 @@ main = customExecParser pp opts >>= \ o -> E.handle h $ case o of

data Options
= Pandoc
| Version
| Shonkier { filename :: String }
| Shonkierjs { filename :: String }
| Page { filename :: String
Expand All @@ -76,6 +79,9 @@ optsParser = subparser
( command' "pandoc"
(pure Pandoc)
"Act as a Pandoc filter"
<> command' "version"
(pure Version)
"Print version and exit"
<> command' "shonkier"
(Shonkier <$> strArgument
(metavar "FILE" <> action "file" <> help "Input Shonkier program."))
Expand Down
18 changes: 18 additions & 0 deletions src/Mary/Version.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{-# LANGUAGE TemplateHaskell #-}

module Mary.Version where

import Control.Monad (guard)

import Data.Version (showVersion)
import Development.GitRev
import qualified Paths_mary as Mary

version :: String
version = showVersion Mary.version ++ maybe "" ('-':) commit

commit :: Maybe String
commit = do
let hash = $(gitHash)
guard (hash /= "UNKNOWN")
pure $ take 7 hash

0 comments on commit a87b8db

Please sign in to comment.