forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogLevelParser.hs
More file actions
59 lines (56 loc) · 1.67 KB
/
LogLevelParser.hs
File metadata and controls
59 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Stack.Options.LogLevelParser
( logLevelOptsParser
) where
import qualified Data.Text as T
import Options.Applicative
( Parser, completeWith, flag', help, long, metavar, short
, strOption
)
import Stack.Options.Utils ( hideMods )
import Stack.Prelude
-- | Parser for a logging level.
logLevelOptsParser :: Bool -> Parser (Maybe LogLevel)
logLevelOptsParser hide = fmap (Just . parse)
(strOption
( long "verbosity"
<> metavar "VERBOSITY"
<> completeWith ["silent", "error", "warn", "info", "debug"]
<> help "Set verbosity level: silent, error, warn, info or debug."
<> hideMods hide
))
<|> flag' (Just verboseLevel)
( short 'v'
<> long "verbose"
<> help
( "Enable verbose mode: verbosity level \""
<> showLevel verboseLevel
<> "\"."
)
<> hideMods hide
)
<|> flag' (Just silentLevel)
( long "silent"
<> help ( "Enable silent mode: verbosity level \""
<> showLevel silentLevel
<> "\"."
)
<> hideMods hide
)
<|> pure Nothing
where
verboseLevel = LevelDebug
silentLevel = LevelOther "silent"
showLevel l = case l of
LevelDebug -> "debug"
LevelInfo -> "info"
LevelWarn -> "warn"
LevelError -> "error"
LevelOther x -> T.unpack x
parse s = case s of
"debug" -> LevelDebug
"info" -> LevelInfo
"warn" -> LevelWarn
"error" -> LevelError
_ -> LevelOther (T.pack s)