1
1
module Main where
2
2
3
- import Control.Monad (forM )
3
+ import Control.Monad (forM_ , forM )
4
4
import Data.Char (toLower , isSpace )
5
5
import Text.Read (readMaybe )
6
6
import System.Directory (createDirectory )
@@ -46,12 +46,13 @@ type ErrorCode = String
46
46
47
47
readCode :: IO ErrorCode
48
48
readCode = do
49
- putStrLn " What is the errorcode that you want to document."
49
+ putStrLn " What is the numeric code that you want to document."
50
+ putStrLn " For example, enter \" 01234\" if you want to document GHC-01234."
50
51
putStr " Input: "
51
52
ln <- getLine
52
53
case (readMaybe ln) :: Maybe Int of
53
54
Nothing -> do
54
- putStrLn " Could not parse the input as an integer. Try again ."
55
+ putStrLn " Could not parse the input as an integer. Only enter the numeric part of the error ."
55
56
readCode
56
57
Just _ -> pure ln
57
58
@@ -97,6 +98,7 @@ type WarningFlag = String
97
98
readWarningFlag :: Severity -> IO (Maybe WarningFlag )
98
99
readWarningFlag Warning = do
99
100
putStrLn " What is the warning flag which enables this warning."
101
+ putStrLn " For example, enter \" -Wtabs\" if you are documenting GHC's warning about tabs in your source file."
100
102
putStr " Input: "
101
103
ln <- getLine
102
104
pure (Just ln)
@@ -107,13 +109,17 @@ type Version = String
107
109
108
110
readVersion :: IO Version
109
111
readVersion = do
110
- putStrLn " For which version was this error message emitted for the first time?"
112
+ putStrLn " Which version of the tool emitted the numeric code (not the message) for the first time?"
111
113
putStrLn " Note: For GHC this is most likely 9.6.1."
112
114
putStr " Input: "
113
115
getLine
114
116
115
117
-- Examples
116
- type Examples = Int
118
+ type Examples = [String ]
119
+
120
+ validateExampleName :: String -> Bool
121
+ validateExampleName " " = False
122
+ validateExampleName str = not (any isSpace str)
117
123
118
124
-- | Only ask for examples if the system is GHC.
119
125
readExamples :: System -> IO Examples
@@ -122,9 +128,16 @@ readExamples GHC = do
122
128
putStr " Input: "
123
129
ln <- getLine
124
130
case (readMaybe ln) :: Maybe Int of
125
- Nothing -> pure 0
126
- Just n -> pure n
127
- readExamples _ = pure 0
131
+ Nothing -> pure []
132
+ (Just n) -> forM [1 .. n] readExample
133
+ readExamples _ = pure []
134
+
135
+ readExample :: Int -> IO String
136
+ readExample i = do
137
+ putStrLn (" Give a name for example " <> show i)
138
+ putStr " Input: "
139
+ ln <- getLine
140
+ if validateExampleName ln then pure ln else readExample i
128
141
129
142
-- Template
130
143
data Template =
@@ -189,8 +202,7 @@ createFiles tmpl = do
189
202
-- - "messages/XXX-NNNNNN/" and "messages/XXX-NNNNNN/index.md"
190
203
-- - "messages/XXX-NNNNNN/before/" and "messages/XXX-NNNNNN/before/Module.hs"
191
204
-- - "messages/XXX-NNNNNN/after/" and "messages/XXX-NNNNNN/after/Module.hs"
192
- forM [1 .. (examples tmpl)] $ \ n -> do
193
- let example = " example" <> show n
205
+ forM_ (examples tmpl) $ \ example -> do
194
206
let example_dir = message_dir </> example
195
207
createDirectory example_dir
196
208
createDirectory (example_dir </> " before" )
@@ -210,7 +222,6 @@ createFiles tmpl = do
210
222
, " -- Insert the fixed example here."
211
223
]
212
224
writeFile (example_dir </> " after" </> " Example.hs" ) after_module
213
- pure ()
214
225
215
226
216
227
-------------------------------------------------------------------------------
0 commit comments