Skip to content

Commit fb7264a

Browse files
committed
Tweak create-message-template output
I highlight the main prompts and provide more info about which files are created. This saved me a little time when I was trying out the script.
1 parent a6e5235 commit fb7264a

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

message-index/create-message-template.hs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Main where
22

33
import Control.Monad (forM, forM_)
44
import Data.Char (isLower, isSpace, toLower, toUpper)
5-
import System.Directory (createDirectory)
5+
import System.Directory (createDirectory, createDirectoryIfMissing)
66
import System.FilePath ((<.>), (</>))
77
import System.IO (BufferMode (..), hSetBuffering, stdout)
88
import Text.Read (readMaybe)
@@ -31,7 +31,7 @@ data Tool = GHC | GHCup | Stack deriving (Show)
3131

3232
readTool :: IO Tool
3333
readTool = do
34-
putStrLn "Which tool's error code do you want to document?"
34+
putStrLn "· Which tool's error code do you want to document?"
3535
putStrLn " 1) GHC"
3636
putStrLn " 2) GHCup"
3737
putStrLn " 3) Stack"
@@ -57,7 +57,7 @@ type ErrorCode = String
5757

5858
readCode :: IO ErrorCode
5959
readCode = do
60-
putStrLn "What is the numeric code that you want to document."
60+
putStrLn "· What is the numeric code that you want to document?"
6161
putStrLn "For example, enter \"01234\" if you want to document GHC-01234."
6262
putStr "Input: "
6363
ln <- getLine
@@ -72,7 +72,7 @@ type Title = String
7272

7373
readTitle :: IO Title
7474
readTitle = do
75-
putStrLn "What is the title of the error message?"
75+
putStrLn "· What is the title of the error message?"
7676
putStrLn "This is used as the title of the documentation page as well as in links to the page."
7777
putStr "Input: "
7878
getLine
@@ -82,7 +82,7 @@ type Summary = String
8282

8383
readSummary :: IO Summary
8484
readSummary = do
85-
putStrLn "Give a short summary of the error message."
85+
putStrLn "· Give a short summary of the error message."
8686
putStrLn "This appears on the overview page that lists all the documented errors and warnings."
8787
putStr "Input: "
8888
getLine
@@ -92,7 +92,7 @@ data Severity = Error | Warning deriving (Show)
9292

9393
readSeverity :: IO Severity
9494
readSeverity = do
95-
putStrLn "What is the severity of the diagnostic."
95+
putStrLn "· What is the severity of the diagnostic?"
9696
putStrLn " 1) Error"
9797
putStrLn " 2) Warning"
9898
putStr "Input (Default = Error): "
@@ -113,7 +113,7 @@ type WarningFlag = String
113113
-- | Only ask for a warning flag if Severity = Warning.
114114
readWarningFlag :: Severity -> IO (Maybe WarningFlag)
115115
readWarningFlag Warning = do
116-
putStrLn "What is the warning flag which enables this warning?"
116+
putStrLn "· What is the warning flag which enables this warning?"
117117
putStrLn "For example, enter \"-Wtabs\" if you are documenting GHC's warning about tabs in your source file."
118118
putStrLn "You can leave this blank if you're not sure."
119119
putStr "Input: "
@@ -125,7 +125,7 @@ type Version = String
125125

126126
readVersion :: IO Version
127127
readVersion = do
128-
putStrLn "Which version of the tool emitted the numeric code (not the message) for the first time?"
128+
putStrLn "· Which version of the tool emitted the numeric code (not the message) for the first time?"
129129
putStrLn "Note: For GHC this is most likely 9.6.1."
130130
putStr "Input: "
131131
getLine
@@ -140,7 +140,7 @@ validateExampleName str@(s : _) = not (any isSpace str) && isLower s
140140
-- | Only ask for examples if the system is GHC.
141141
readExamples :: Tool -> IO Examples
142142
readExamples GHC = do
143-
putStrLn "How many examples should be generated?"
143+
putStrLn "· How many examples should be generated?"
144144
putStr "Input: "
145145
ln <- getLine
146146
case readMaybe ln :: Maybe Int of
@@ -150,7 +150,8 @@ readExamples _ = pure []
150150

151151
readExample :: Int -> IO String
152152
readExample i = do
153-
putStrLn ("Give a name for example " <> show i)
153+
putStrLn ""
154+
putStrLn ("· Give a name for example " <> show i)
154155
putStrLn "The name should not contain spaces and begin with a lowercase letter."
155156
putStr "Input: "
156157
ln <- getLine
@@ -197,13 +198,13 @@ readTemplate = do
197198

198199
createFiles :: Template -> IO ()
199200
createFiles tmpl = do
200-
putStrLn "Creating scaffolding for the following configuration:"
201-
print tmpl
202201
putStrLn ""
202+
putStrLn "· Creating scaffolding..."
203203

204204
-- Create the new directory "messages/XXX-NNNNNN/" and "messages/XXX-NNNNNN/index.md"
205205
let message_dir = "messages" </> case tool tmpl of { GHC -> "GHC-"; GHCup -> "GHCup-"; Stack -> "S-" } ++ code tmpl
206-
createDirectory message_dir
206+
createDirectoryIfMissing True message_dir
207+
let index_filename = message_dir </> "index.md"
207208
let toplvl_index =
208209
unlines
209210
[ "---",
@@ -215,7 +216,10 @@ createFiles tmpl = do
215216
"",
216217
"Insert your error message here."
217218
]
218-
writeFile (message_dir </> "index.md") toplvl_index
219+
writeFile index_filename toplvl_index
220+
putStrLn ("·· Created file " <> index_filename <> " with these contents:")
221+
putStrLn ""
222+
putStr toplvl_index
219223

220224
-- Create the example directories and entries:
221225
-- - "messages/XXX-NNNNNN/" and "messages/XXX-NNNNNN/example-name/index.md"
@@ -227,6 +231,7 @@ createFiles tmpl = do
227231
uppercase (s : ss) = toUpper s : ss
228232
let example_name = uppercase example
229233
createDirectory example_dir
234+
putStrLn ("·· Creating blank example in directory " <> example_dir <> "...")
230235
createDirectory (example_dir </> "before")
231236
createDirectory (example_dir </> "after")
232237
let example_index =

0 commit comments

Comments
 (0)