From 652c2030c5ef39bf1dd34d26064e1059431898f0 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 9 Nov 2021 20:24:17 +0100 Subject: first example of a map adjustment this also includes some more monad plumbing, and an option for the linter to actually write things out again. Some of the previous commit was reverted a bit since it turned out to be stupid, but overall it was suprisingly easy once I got around to it, so yay! i guess Also includes a fairly silly example of how to use it. --- src/Main.hs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Main.hs b/src/Main.hs index f4060b9..0e80eab 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -6,16 +6,17 @@ module Main where -import Data.Aeson (encode) -import Data.Aeson.Encode.Pretty (encodePretty) -import qualified Data.ByteString.Lazy as LB -import qualified Data.ByteString.Char8 as C8 -import Data.Maybe (fromMaybe) +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 Util (printPretty) -import CheckDir (recursiveCheckDir) -import Types (Level(..)) +import CheckDir (recursiveCheckDir, + writeAdjustedRepository) +import Types (Level (..)) +import Util (printPretty) -- | the options this cli tool can take data Options = Options @@ -27,10 +28,11 @@ data Options = Options -- ^ pass --allowScripts to allow javascript in map , json :: Bool -- ^ emit json if --json was given - , lintlevel :: Maybe Level + , 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) @@ -45,6 +47,10 @@ run options = do lints <- recursiveCheckDir repo entry + case out options of + Just path -> writeAdjustedRepository path lints + Nothing -> pure () + if json options then printLB $ if pretty options then encodePretty lints else encode lints -- cgit v1.2.3