diff --git a/src/Main.hs b/src/Main.hs index 32afb6ab98a89a4984b28942aeb7e26777c0c203..9bc09ffa19084d695a9b3bf4e2ae913ee8852415 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -12,17 +12,19 @@ import Data.Aeson (eitherDecode, encode) import Data.Aeson.Encode.Pretty (encodePretty) import Data.Aeson.KeyMap (coercionToHashMap) import qualified Data.ByteString.Lazy as LB -import qualified Data.Text.Encoding as T -import qualified Data.Text.IO as T import Data.Maybe (fromMaybe) +import qualified Data.Text.Encoding as T +import qualified Data.Text.IO as T import System.Exit (ExitCode (..), exitWith) import WithCli import CheckDir (recursiveCheckDir, resultIsFatal) +import Control.Monad (when) import LintConfig (LintConfig (..), patchConfig) import System.IO (hPutStrLn, stderr) import Types (Level (..)) import Util (printPretty) +import qualified Version as V (version) import WriteRepo (writeAdjustedRepository) -- | the options this cli tool can take @@ -43,6 +45,7 @@ data Options = Options -- ^ path to a config file. Currently required. , config :: Maybe (LintConfig Maybe) -- ^ a "patch" for the configuration file + , version :: Bool } deriving (Show, Generic, HasArguments) @@ -53,6 +56,10 @@ run :: Options -> IO () run options = do aesonWarning + when (version options) $ do + putStrLn V.version + exitWith ExitSuccess + let repo = fromMaybe "." (repository options) let entry = fromMaybe "main.json" (entrypoint options) let level = fromMaybe Suggestion (lintlevel options) diff --git a/src/Version.hs b/src/Version.hs new file mode 100644 index 0000000000000000000000000000000000000000..6679ae12089a0bd3be40c74a2010b88475bba712 --- /dev/null +++ b/src/Version.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE TemplateHaskell #-} + + +module Version ( version ) where + +import Control.Monad.Trans (liftIO) +import qualified Language.Haskell.TH as TH +import System.Process (readProcess) + +version :: String +version = "walint rc3 2021 (" <> + $(do + hash <- liftIO $ readProcess "git" ["rev-parse", "HEAD"] "" + pure . TH.LitE . TH.StringL $ take 40 hash) ++ + ")" diff --git a/walint.cabal b/walint.cabal index c189dda6f2d5b915d32f9883b8e69fd7c5ebf5c8..5e12d0135d91a2580069869e1723068142c9b0eb 100644 --- a/walint.cabal +++ b/walint.cabal @@ -68,6 +68,9 @@ executable walint aeson-pretty, bytestring, mtl, - text + text, + template-haskell, + process hs-source-dirs: src default-language: Haskell2010 + other-modules: Version