Created
May 1, 2024 13:08
-
-
Save KaneTW/586cd308736803efeca37fa6cb59f2d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TemplateHaskell #-} | |
import VerifySchema | |
import Hasql.Connection | |
import System.Environment (getArgs, lookupEnv, getEnvironment) | |
import qualified Data.ByteString.Char8 as BS | |
import Kea.Model | |
import GetSchemas | |
import Data.Maybe (maybeToList) | |
import Data.List (intercalate) | |
import Control.Exception (throwIO) | |
verifiers :: [ReaderT CheckEnv (Accum CheckResults) ()] | |
verifiers = $(do | |
schemas <- runIO getKeaModelSchemas | |
let exps = map (\sch -> [| verifySchema $(varE $ mkName sch)|] ) schemas | |
listE exps) | |
renderLabelWithContext :: String -> [String] -> String -> String | |
renderLabelWithContext label ctx msg | |
= label ++ " (" ++ intercalate "." ctx ++ "): " ++ msg | |
printWarning :: Warning -> IO () | |
printWarning warn = putStrLn $ renderLabelWithContext "Warning" warn.ctx warn.warning | |
printError :: Error -> IO () | |
printError err = putStrLn $ renderLabelWithContext "Error" err.ctx err.error | |
printResults :: CheckResults -> IO () | |
printResults res = do | |
mapM_ printWarning res.warnings | |
mapM_ printError res.errors | |
main :: IO () | |
main = do | |
args <- getArgs | |
maybeConn <- acquire . BS.pack $ unwords args | |
conn <- case maybeConn of | |
Right conn -> return conn | |
Left err -> fail (show err) | |
env <- fetchCheckEnv conn | |
let results = execAccum (runReaderT (sequence verifiers) env) mempty | |
printResults results | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment