blob: 969fa10329a42ae4b1f5d7a679aec2fec818a863 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
{-# 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.Lazy as LB
import qualified Data.ByteString.Lazy.Encoding as LB
import Data.Maybe (fromMaybe)
import Data.Text.Lazy as T
import System.IO (utf8)
import WithCli
import CheckMap (loadAndLintMap)
import Util (printPretty)
-- | 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
lints <- loadAndLintMap (fromMaybe "example.json" (inpath options))
if json options
then printLB
$ if pretty options then encodePretty lints else encode lints
else printPretty lints
-- | haskell's many string types are FUN …
printLB :: LB.ByteString -> IO ()
printLB = putStrLn . T.unpack . LB.decode utf8
|