diff options
author | stuebinm | 2021-11-14 02:27:36 +0100 |
---|---|---|
committer | stuebinm | 2021-11-14 02:27:36 +0100 |
commit | 34e66b3ab80fb201f49998ab46bb7a35370012c0 (patch) | |
tree | 01a790f048eb0f3ed1197c6ba0edc9e665b94fa7 /src | |
parent | 0b29a7e82a8c2dcf9ce4f2fba3ec07896fa72397 (diff) |
too much type level stuff to read a config file
This got kinda out of hand, but it can now (a) read a json config file
and (b) patch that with another json given on the command line to change
some of the options given in the file.
No, I probably didn't need to make the `patch` function sufficiently
general to work with arbitrary records, but it was kinda fun to do.
Diffstat (limited to '')
-rw-r--r-- | src/Main.hs | 22 |
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 |