1
1
module Main where
2
2
3
3
import Control.Monad (forM )
4
+ import Data.Char (toLower , isSpace )
4
5
import Text.Read (readMaybe )
5
6
import System.Directory (createDirectory )
6
7
import System.FilePath ((</>) )
@@ -9,6 +10,13 @@ import System.FilePath ((</>))
9
10
-- Querying the user about the diagnostic
10
11
-------------------------------------------------------------------------------
11
12
13
+ -- | Remove leading and trailing whitespace, and convert to lower case.
14
+ normalize :: String -> String
15
+ normalize = fmap toLower . strip
16
+ where
17
+ strip = f . f
18
+ f = reverse . dropWhile isSpace
19
+
12
20
-- Querying for the system: GHC / GHCup / Stack
13
21
14
22
data System = GHC | GHCup | Stack deriving Show
@@ -21,13 +29,13 @@ readSystem = do
21
29
putStrLn " 3) Stack"
22
30
putStr " Input (Default = GHC): "
23
31
ln <- getLine
24
- case ln of
32
+ case normalize ln of
25
33
" 1" -> pure GHC
26
- " GHC " -> pure GHC
34
+ " ghc " -> pure GHC
27
35
" 2" -> pure GHCup
28
- " GHCup " -> pure GHCup
36
+ " ghcup " -> pure GHCup
29
37
" 3" -> pure Stack
30
- " Stack " -> pure Stack
38
+ " stack " -> pure Stack
31
39
_ -> pure GHC
32
40
33
41
-- Querying for the error code
@@ -66,22 +74,21 @@ readSummary = do
66
74
getLine
67
75
68
76
-- Severity
69
- data Severity = Error | Warning | NA deriving Show
77
+ data Severity = Error | Warning deriving Show
70
78
71
79
readSeverity :: IO Severity
72
80
readSeverity = do
73
81
putStrLn " What is the severity of the diagnostic."
74
82
putStrLn " 1) Error"
75
83
putStrLn " 2) Warning"
76
- putStrLn " 3) N/A"
77
- putStr " Input (Default = N/A): "
84
+ putStr " Input (Default = Error): "
78
85
ln <- getLine
79
- case ln of
86
+ case normalize ln of
80
87
" 1" -> pure Error
81
- " Error " -> pure Error
88
+ " error " -> pure Error
82
89
" 2" -> pure Warning
83
- " Warning " -> pure Warning
84
- _ -> pure NA
90
+ " warning " -> pure Warning
91
+ _ -> pure Error
85
92
86
93
-- Warning flag
87
94
type WarningFlag = String
@@ -170,7 +177,7 @@ createFiles tmpl = do
170
177
let toplvl_index = unlines [ " ---"
171
178
, " title: " <> title tmpl
172
179
, " summary: " <> summary tmpl
173
- , " severity: " <> case severity tmpl of { Warning -> " warning" ; Error -> " error" ; NA -> " na " }
180
+ , " severity: " <> case severity tmpl of { Warning -> " warning" ; Error -> " error" }
174
181
, " introduced: " <> introduced tmpl
175
182
, " ---"
176
183
, " "
0 commit comments