summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorstuebinm2021-12-22 21:45:45 +0100
committerstuebinm2021-12-22 21:45:45 +0100
commitebfc8be95e83852081d8dc93d2bf4717df18583e (patch)
treed7a70d354046e9d6d4dc8ec0fd73bc46e60c3b40 /src
parente8fca76246a313f743180408c5745cb050d1d1a6 (diff)
print version information on --version
If --version is given, `walint` prints version information, then exists with code 0.
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs11
-rw-r--r--src/Version.hs15
2 files changed, 24 insertions, 2 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) ++
+ ")"