{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} module Main where import Data.Aeson (encode) import Data.Aeson.Encode.Pretty (encodePretty) import qualified Data.ByteString.Char8 as C8 import qualified Data.ByteString.Lazy as LB import Data.Maybe (fromMaybe) import WithCli import CheckDir (recursiveCheckDir) import WriteRepo (writeAdjustedRepository) import Types (Level (..)) import Util (printPretty) -- | the options this cli tool can take data Options = Options { repository :: Maybe String -- ^ path to the repository containing maps to lint , entrypoint :: Maybe String -- ^ entrypoint in that repository , allowScripts :: Bool -- ^ pass --allowScripts to allow javascript in map , json :: Bool -- ^ emit json if --json was given , lintlevel :: Maybe Level -- ^ maximum lint level to print , pretty :: Bool -- ^ pretty-print the json to make it human-readable , out :: Maybe String } deriving (Show, Generic, HasArguments) main :: IO () main = withCli run run :: Options -> IO () run options = do let repo = fromMaybe "." (repository options) let entry = fromMaybe "main.json" (entrypoint options) let level = fromMaybe Suggestion (lintlevel options) lints <- recursiveCheckDir repo entry case out options of Just outpath -> writeAdjustedRepository repo outpath lints Nothing -> pure () if json options then printLB $ if pretty options then encodePretty lints else encode lints else printPretty (level, lints) -- | haskell's many string types are FUN … printLB :: LB.ByteString -> IO () printLB a = putStrLn $ C8.unpack $ LB.toStrict a