Commit 127677f5 authored by Michael Hanus 's avatar Michael Hanus
Browse files

CPM updated

parent 14ef157f
......@@ -38,7 +38,8 @@ logLevelOf :: LogEntry -> LogLevel
logLevelOf (LogEntry ll _) = ll
--- A log level.
data LogLevel = Info
data LogLevel = Quiet
| Info
| Debug
| Error
| Critical
......@@ -142,6 +143,7 @@ showLogEntry (LogEntry lvl msg) = do
else return ()
where
lvlText = case lvl of
Quiet -> text "QUIET " -- show not occur...
Info -> text "INFO "
Debug -> green $ text "DEBUG "
Critical -> red $ text "CRITICAL "
......@@ -150,19 +152,28 @@ showLogEntry (LogEntry lvl msg) = do
--- Compares two log levels.
levelGte :: LogLevel -> LogLevel -> Bool
levelGte Debug Debug = True
levelGte Debug Quiet = False
levelGte Debug Info = False
levelGte Debug Error = False
levelGte Debug Critical = False
levelGte Info Debug = True
levelGte Info Info = True
levelGte Info Quiet = False
levelGte Info Error = False
levelGte Info Critical = False
levelGte Quiet Debug = True
levelGte Quiet Quiet = True
levelGte Quiet Info = False
levelGte Quiet Error = False
levelGte Quiet Critical = False
levelGte Error Debug = True
levelGte Error Info = True
levelGte Error Quiet = True
levelGte Error Error = True
levelGte Error Critical = True
levelGte Critical Debug = True
levelGte Critical Info = True
levelGte Critical Quiet = True
levelGte Critical Error = True
levelGte Critical Critical = True
......
......@@ -310,6 +310,7 @@ readLogLevel :: String -> Either String LogLevel
readLogLevel s = case map toLower s of
"debug" -> Right Debug
"info" -> Right Info
"quiet" -> Right Quiet
_ -> Left $ "Illegal verbosity value: " ++ s
readRcOption :: String -> Either String (String,String)
......@@ -342,10 +343,10 @@ a >.> f = case a of
optionParser :: [String] -> ParseSpec (Options -> Either String Options)
optionParser allargs = optParser
( option (\s a -> readLogLevel s >.> \ll -> a { optLogLevel = ll })
( long "verbosity"
<> short "v"
<> metavar "LEVEL"
<> help "Log level for the application. Valid values are 'info' and 'debug'." )
( long "verbosity"
<> short "v"
<> metavar "LEVEL"
<> help "Log level for the application. Valid values: info|debug|quiet" )
<.> option (\s a -> readRcOption s >.> \kv ->
a { optDefConfig = optDefConfig a ++ [kv] })
( long "define"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment