{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} module Main where import Data.Maybe (fromMaybe) import WithCli import CheckMap (runLinter) import Data.Aeson (encode) import Data.Aeson.Encode.Pretty (encodePretty) import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Lazy.Encoding as LB import Data.Text.Lazy as T import System.IO (utf8) import Tiled2 -- | the options this cli tool can take data Options = Options { inpath :: Maybe String -- ^ path to input map files , outpath :: Maybe String -- ^ path to out directory (should be empty) , allowScripts :: Bool -- ^ pass --allowScripts to allow javascript in map , scriptInject :: Maybe String -- ^ optional filepath to javascript that should be injected , json :: Bool -- ^ emit json if --json was given , pretty :: Bool -- ^ pretty-print the json to make it human-readable } deriving (Show, Generic, HasArguments) main :: IO () main = withCli run run :: Options -> IO () run options = do -- TODO: what if parsing fails and we get Left err? Right waMap <- loadTiledmap $ fromMaybe "example.json" (inpath options) let lints = runLinter waMap if json options then printLB $ if pretty options then encodePretty lints else encode lints else print lints -- | haskell's many string types are FUN … printLB :: LB.ByteString -> IO () printLB = putStrLn . T.unpack . LB.decode utf8