Skip to content

Commit a87b8db

Browse files
committed
[ new ] version command (with git hash)
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
1 parent b3d604f commit a87b8db

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

mary.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ library
6565
, containers >=0.6 && <0.7
6666
, directory >=1.3.3.0 && <1.3.3.4
6767
, filepath >=1.4.2.1 && <1.4.3
68+
, gitrev >=1.0 && <1.4
6869
, hs-php-session >=0.0.9.3 && <0.0.10
6970
, mtl >=2 && <3
7071
, newtype >=0.2 && <0.3
@@ -81,6 +82,7 @@ library
8182
, Mary.Pandoc
8283
, Mary.ServePage
8384
, Mary.Find
85+
, Mary.Version
8486
, Shonkier
8587
, Shonkier.Examples
8688
, Shonkier.FreeVars
@@ -99,6 +101,8 @@ library
99101
, Shonkier.Value
100102
, Utils.List
101103

104+
other-modules: Paths_mary
105+
102106
-- LANGUAGE extensions used by modules in this package.
103107
-- other-extensions:
104108

mary.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Data.List as L
66
import Data.Maybe
77
import Data.Semigroup ((<>))
88
import Data.Text
9-
import Data.Text.IO as TIO
9+
import qualified Data.Text.IO as TIO
1010

1111
import Text.Pandoc.JSON (toJSONFilter)
1212

@@ -20,8 +20,9 @@ import Shonkier
2020
import Mary.Pandoc
2121
import Mary.ServePage
2222
import Mary.Find
23+
import Mary.Version
2324

24-
import Paths_mary
25+
import Paths_mary (getDataFileName)
2526

2627
defaultUser :: IO String
2728
defaultUser = do
@@ -31,6 +32,7 @@ defaultUser = do
3132
main :: IO ()
3233
main = customExecParser pp opts >>= \ o -> E.handle h $ case o of
3334
Pandoc -> toJSONFilter process
35+
Version -> putStrLn version
3436
Shonkier filename -> interpretShonkier filename
3537
Shonkierjs filename -> do
3638
shonkierjs <- getDataFileName "src/data-dir/Shonkier.js"
@@ -58,6 +60,7 @@ main = customExecParser pp opts >>= \ o -> E.handle h $ case o of
5860

5961
data Options
6062
= Pandoc
63+
| Version
6164
| Shonkier { filename :: String }
6265
| Shonkierjs { filename :: String }
6366
| Page { filename :: String
@@ -76,6 +79,9 @@ optsParser = subparser
7679
( command' "pandoc"
7780
(pure Pandoc)
7881
"Act as a Pandoc filter"
82+
<> command' "version"
83+
(pure Version)
84+
"Print version and exit"
7985
<> command' "shonkier"
8086
(Shonkier <$> strArgument
8187
(metavar "FILE" <> action "file" <> help "Input Shonkier program."))

src/Mary/Version.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
3+
module Mary.Version where
4+
5+
import Control.Monad (guard)
6+
7+
import Data.Version (showVersion)
8+
import Development.GitRev
9+
import qualified Paths_mary as Mary
10+
11+
version :: String
12+
version = showVersion Mary.version ++ maybe "" ('-':) commit
13+
14+
commit :: Maybe String
15+
commit = do
16+
let hash = $(gitHash)
17+
guard (hash /= "UNKNOWN")
18+
pure $ take 7 hash

0 commit comments

Comments
 (0)