Skip to content
Snippets Groups Projects
Commit ebfc8be9 authored by stuebinm's avatar stuebinm
Browse files

print version information on --version

If --version is given, `walint` prints version information, then exists
with code 0.
parent e8fca762
No related branches found
No related tags found
No related merge requests found
Pipeline #10943 passed
...@@ -12,17 +12,19 @@ import Data.Aeson (eitherDecode, encode) ...@@ -12,17 +12,19 @@ import Data.Aeson (eitherDecode, encode)
import Data.Aeson.Encode.Pretty (encodePretty) import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Aeson.KeyMap (coercionToHashMap) import Data.Aeson.KeyMap (coercionToHashMap)
import qualified Data.ByteString.Lazy as LB 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 Data.Maybe (fromMaybe)
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
import System.Exit (ExitCode (..), exitWith) import System.Exit (ExitCode (..), exitWith)
import WithCli import WithCli
import CheckDir (recursiveCheckDir, resultIsFatal) import CheckDir (recursiveCheckDir, resultIsFatal)
import Control.Monad (when)
import LintConfig (LintConfig (..), patchConfig) import LintConfig (LintConfig (..), patchConfig)
import System.IO (hPutStrLn, stderr) import System.IO (hPutStrLn, stderr)
import Types (Level (..)) import Types (Level (..))
import Util (printPretty) import Util (printPretty)
import qualified Version as V (version)
import WriteRepo (writeAdjustedRepository) import WriteRepo (writeAdjustedRepository)
-- | the options this cli tool can take -- | the options this cli tool can take
...@@ -43,6 +45,7 @@ data Options = Options ...@@ -43,6 +45,7 @@ data Options = Options
-- ^ path to a config file. Currently required. -- ^ path to a config file. Currently required.
, config :: Maybe (LintConfig Maybe) , config :: Maybe (LintConfig Maybe)
-- ^ a "patch" for the configuration file -- ^ a "patch" for the configuration file
, version :: Bool
} deriving (Show, Generic, HasArguments) } deriving (Show, Generic, HasArguments)
...@@ -53,6 +56,10 @@ run :: Options -> IO () ...@@ -53,6 +56,10 @@ run :: Options -> IO ()
run options = do run options = do
aesonWarning aesonWarning
when (version options) $ do
putStrLn V.version
exitWith ExitSuccess
let repo = fromMaybe "." (repository options) let repo = fromMaybe "." (repository options)
let entry = fromMaybe "main.json" (entrypoint options) let entry = fromMaybe "main.json" (entrypoint options)
let level = fromMaybe Suggestion (lintlevel options) let level = fromMaybe Suggestion (lintlevel options)
......
{-# 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) ++
")"
...@@ -68,6 +68,9 @@ executable walint ...@@ -68,6 +68,9 @@ executable walint
aeson-pretty, aeson-pretty,
bytestring, bytestring,
mtl, mtl,
text text,
template-haskell,
process
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010
other-modules: Version
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment