diff options
author | stuebinm | 2022-02-18 18:09:23 +0100 |
---|---|---|
committer | stuebinm | 2022-03-19 19:54:48 +0100 |
commit | 52bf0fa6dace596a4bd5b4e4229fbb9704fbf443 (patch) | |
tree | 971604d125e2faba93db8845224a2d43ee645935 /src | |
parent | 53fb449b008e9b6aed9877b9d33f4026e454e0f9 (diff) |
switch to universum prelude
also don't keep adjusted maps around if not necessary
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.hs | 30 | ||||
-rw-r--r-- | src/Version.hs | 4 |
2 files changed, 15 insertions, 19 deletions
diff --git a/src/Main.hs b/src/Main.hs index f0a6c09..bf39564 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -7,18 +7,15 @@ module Main where -import Control.Monad (unless, when) -import Control.Monad.Identity (Identity) +import Universum + import Data.Aeson (eitherDecode, encode) import Data.Aeson.Encode.Pretty (encodePretty) import Data.Aeson.KeyMap (coercionToHashMap) import qualified Data.ByteString.Lazy as LB -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.IO (hPutStrLn, stderr) -import WithCli (Generic, HasArguments, withCli) +import WithCli (HasArguments, withCli) import CheckDir (recursiveCheckDir, resultIsFatal, DirResult (dirresultGraph)) import Control.Monad (when) @@ -28,6 +25,7 @@ import Util (printPretty) import WriteRepo (writeAdjustedRepository) import Text.Dot (showDot) +import System.Exit (ExitCode (ExitFailure, ExitSuccess)) import qualified Version as V (version) -- | the options this cli tool can take @@ -62,7 +60,7 @@ run options = do when (version options) $ do putStrLn V.version - exitWith ExitSuccess + exitSuccess let repo = fromMaybe "." (repository options) let entry = fromMaybe "main.json" (entrypoint options) @@ -72,7 +70,7 @@ run options = do Nothing -> error "Need a config file!" Just path -> LB.readFile path >>= \res -> case eitherDecode res :: Either String (LintConfig Identity) of - Left err -> error $ "config file invalid: " <> err + Left err -> error $ "config file invalid: " <> toText err Right file -> pure (patchConfig file (config options)) lints <- recursiveCheckDir lintconfig repo entry @@ -85,16 +83,14 @@ run options = do | otherwise -> printPretty (level, lints) case out options of - Nothing -> exitWith $ case resultIsFatal lintconfig lints of - False -> ExitSuccess - True -> ExitFailure 1 + Nothing -> exitWith $ if resultIsFatal lintconfig lints then ExitFailure 1 else ExitSuccess Just outpath -> do c <- writeAdjustedRepository lintconfig repo outpath lints unless (json options) $ case c of - ExitFailure 1 -> putStrLn "\nMap failed linting!" - ExitFailure 2 -> putStrLn "\nOutpath already exists, not writing anything." - _ -> pure () + ExitFailure 1 -> putTextLn "\nMap failed linting!" + ExitFailure 2 -> putTextLn "\nOutpath already exists, not writing anything." + _ -> pass exitWith c @@ -113,10 +109,10 @@ printLB a = T.putStrLn $ T.decodeUtf8 $ LB.toStrict a aesonWarning :: IO () aesonWarning = case coercionToHashMap of Just _ -> hPutStrLn stderr - "Warning: this program was compiled using an older version of the Aeson Library\n\ + ("Warning: this program was compiled using an older version of the Aeson Library\n\ \used for parsing JSON, which is susceptible to hash flooding attacks.\n\ \n\ \Recompiling with a newer version is recommended when handling untrusted inputs.\n\ \n\ - \See https://cs-syd.eu/posts/2021-09-11-json-vulnerability for details." - _ -> pure () + \See https://cs-syd.eu/posts/2021-09-11-json-vulnerability for details." :: Text) + _ -> pass diff --git a/src/Version.hs b/src/Version.hs index c0f7edf..2ec1537 100644 --- a/src/Version.hs +++ b/src/Version.hs @@ -3,10 +3,10 @@ module Version ( version ) where -import Control.Monad.Trans (liftIO) +import Universum + import qualified Language.Haskell.TH as TH import System.Process (readProcess) -import GHC.IO (catchAny) version :: String version = "walint rc3 2021 (" <> |