summaryrefslogtreecommitdiff
path: root/lib/Types.hs
diff options
context:
space:
mode:
authorstuebinm2021-09-23 04:34:02 +0200
committerstuebinm2021-09-23 04:34:58 +0200
commit68af04a4da6ba4ec61d1469337ce53457526d861 (patch)
treecb882c03ebe2c88450f16702cd4467a73e2c22a3 /lib/Types.hs
parent04b98e4d62fe33b4fa357f2b52ffcc4f2c413302 (diff)
prettier pretty printing and stuff
also, configurable log level, which only required relaxing the type system once!
Diffstat (limited to '')
-rw-r--r--lib/Types.hs28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/Types.hs b/lib/Types.hs
index 5ec91a0..b609012 100644
--- a/lib/Types.hs
+++ b/lib/Types.hs
@@ -17,11 +17,31 @@ import GHC.Generics (Generic)
import qualified Data.Aeson as A
import Paths (RelPath)
import Util (PrettyPrint (..), showText)
+import WithCli (Argument, Proxy (..),
+ atomicArgumentsParser)
+import WithCli.Pure (Argument (argumentType, parseArgument),
+ HasArguments (argumentsParser))
+
-- | Levels of errors and warnings, collectively called
-- "Hints" until I can think of some better name
-data Level = Warning | Suggestion | Info | Forbidden | Error | Fatal
- deriving (Show, Generic, ToJSON)
+data Level = Info | Suggestion | Warning | Forbidden | Error | Fatal
+ deriving (Show, Generic, ToJSON, Ord, Eq, A.FromJSON)
+
+instance Argument Level where
+ argumentType Proxy = "Lint Level"
+ parseArgument arg = case arg of
+ "info" -> Just Info
+ "suggestion" -> Just Suggestion
+ "warning" -> Just Warning
+ "forbidden" -> Just Forbidden
+ "error" -> Just Error
+ "fatal" -> Just Fatal
+ _ -> Nothing
+
+
+instance HasArguments Level where
+ argumentsParser = atomicArgumentsParser
-- | a hint comes with an explanation (and a level), or is a dependency
-- (in which case it'll be otherwise treated as an info hint)
@@ -48,9 +68,9 @@ lintLevel (Depends _) = Info
instance PrettyPrint Lint where
prettyprint (Lint Hint { hintMsg, hintLevel } ) =
- showText hintLevel <> ": " <> hintMsg
+ " " <> showText hintLevel <> ": " <> hintMsg
prettyprint (Depends dep) =
- "Info: found dependency: " <> prettyprint dep
+ " Info: found dependency: " <> prettyprint dep
instance ToJSON Lint where
toJSON (Lint l) = toJSON l