diff options
author | stuebinm | 2021-12-22 21:45:45 +0100 |
---|---|---|
committer | stuebinm | 2021-12-22 21:45:45 +0100 |
commit | ebfc8be95e83852081d8dc93d2bf4717df18583e (patch) | |
tree | d7a70d354046e9d6d4dc8ec0fd73bc46e60c3b40 | |
parent | e8fca76246a313f743180408c5745cb050d1d1a6 (diff) |
print version information on --version
If --version is given, `walint` prints version information, then exists
with code 0.
-rw-r--r-- | src/Main.hs | 11 | ||||
-rw-r--r-- | src/Version.hs | 15 | ||||
-rw-r--r-- | walint.cabal | 5 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/Main.hs b/src/Main.hs index 32afb6a..9bc09ff 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 0000000..6679ae1 --- /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 c189dda..5e12d01 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 |