summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 9fefd82..5dcf13c 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -6,7 +6,7 @@
module Main where
-import Data.Aeson (encode)
+import Data.Aeson (eitherDecode, encode)
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Char8 as C8
import qualified Data.ByteString.Lazy as LB
@@ -14,10 +14,12 @@ import Data.Maybe (fromMaybe)
import WithCli
import CheckDir (recursiveCheckDir)
-import WriteRepo (writeAdjustedRepository)
+import Control.Monad.Identity (Identity)
+import LintConfig (LintConfig (..), patch)
+import System.Exit (exitWith)
import Types (Level (..))
import Util (printPretty)
-import System.Exit (exitWith)
+import WriteRepo (writeAdjustedRepository)
-- | the options this cli tool can take
data Options = Options
@@ -34,6 +36,8 @@ data Options = Options
, pretty :: Bool
-- ^ pretty-print the json to make it human-readable
, out :: Maybe String
+ , config :: Maybe (LintConfig Maybe)
+ , configFile :: Maybe FilePath
} deriving (Show, Generic, HasArguments)
@@ -45,6 +49,18 @@ run options = do
let repo = fromMaybe "." (repository options)
let entry = fromMaybe "main.json" (entrypoint options)
let level = fromMaybe Suggestion (lintlevel options)
+ print (config options)
+
+ lintconfig <- case configFile options of
+ Nothing -> error "Need a config file!"
+ Just path -> LB.readFile path >>= \res ->
+ case eitherDecode res :: Either String (LintConfig Identity) of
+ Left err -> error $ "config file invalid: " <> err
+ Right file -> case config options of
+ Just p -> pure (patch file p)
+ Nothing -> pure file
+
+ print lintconfig
lints <- recursiveCheckDir repo entry