Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 903d1f9

Browse files
committed
Create help message programmatically
1 parent 0a87cf1 commit 903d1f9

File tree

1 file changed

+47
-35
lines changed

1 file changed

+47
-35
lines changed

install.hs

+47-35
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type VersionNumber = String
3030
type GhcPath = String
3131

3232
-- |Defines all different hie versions that are buildable.
33-
-- If they are edited,
33+
-- If they are edited, make sure to maintain the order of the versions.
3434
hieVersions :: [VersionNumber]
3535
hieVersions =
3636
["8.2.1", "8.2.2", "8.4.2", "8.4.3", "8.4.4", "8.6.1", "8.6.2", "8.6.3"]
@@ -62,11 +62,8 @@ main = do
6262
phony "test" (forM_ hieVersions test)
6363
phony "build-copy-compiler-tool" $ forM_ hieVersions buildCopyCompilerTool
6464

65-
forM_
66-
hieVersions
67-
(\version -> phony ("build-doc-hie-" ++ version) $ do
68-
buildDoc version
69-
)
65+
forM_ hieVersions
66+
(\version -> phony ("build-doc-hie-" ++ version) $ buildDoc version)
7067

7168
forM_
7269
hieVersions
@@ -148,14 +145,14 @@ buildHie :: VersionNumber -> Action ()
148145
buildHie versionNumber = do
149146
when (versionNumber `elem` ["hie-8.2.2", "hie-8.2.1"])
150147
$ execStackWithYaml_ versionNumber ["install", "happy"]
151-
(execStackWithYaml_ versionNumber ["build"]) `actionOnException`
152-
liftIO (putStrLn buildFailMsg)
148+
execStackWithYaml_ versionNumber ["build"]
149+
`actionOnException` liftIO (putStrLn buildFailMsg)
153150

154151
buildFailMsg :: String
155152
buildFailMsg =
156-
let starsLine = "\n******************************************************************\n"
157-
in
158-
starsLine
153+
let starsLine
154+
= "\n******************************************************************\n"
155+
in starsLine
159156
++ "building failed, "
160157
++ "try running `stack clean` and restart the build\n"
161158
++ "if this does not work, open an issue at \n"
@@ -187,36 +184,51 @@ buildDoc versionNumber = do
187184

188185
helpMessage :: Action ()
189186
helpMessage = do
190-
let out = liftIO . putStrLn
191187
scriptName <- liftIO getProgName
192188
out ""
193189
out "Usage:"
194-
out (" stack " <> scriptName <> " <target>")
190+
out' ("stack " <> scriptName <> " <target>")
195191
out ""
196192
out "Targets:"
197-
out
198-
" build Builds hie for all supported GHC versions (8.2.1, 8.2.2, 8.4.2, 8.4.3, 8.4.4, 8.6.1, 8.6.2 and 8.6.3)"
199-
out
200-
" build-all Builds hie and hoogle databases for all supported GHC versions"
201-
out " hie-8.2.1 Builds hie for GHC version 8.2.1 only"
202-
out " hie-8.2.2 Builds hie for GHC version 8.2.2 only"
203-
out " hie-8.4.2 Builds hie for GHC version 8.4.2 only"
204-
out " hie-8.4.3 Builds hie for GHC version 8.4.3 only"
205-
out " hie-8.4.4 Builds hie for GHC version 8.4.4 only"
206-
out " hie-8.6.1 Builds hie for GHC version 8.6.1 only"
207-
out " hie-8.6.2 Builds hie for GHC version 8.6.2 only"
208-
out " hie-8.6.3 Builds hie for GHC version 8.6.3 only"
209-
out " submodules Updates local git submodules"
210-
out
211-
" cabal NOTE 3: This is needed for stack only projects too"
212-
out
213-
" build-docs Builds the Hoogle database for all supported GHC versions"
214-
out " test Runs hie tests"
215-
out " icu-macos-fix Fixes icu related problems in MacOS"
216-
out
217-
" dist Creates a tarball containing all the hie binaries"
218-
out " help Show help"
193+
mapM_ (out' . showTarget) targets
219194
out ""
195+
where
196+
out = liftIO . putStrLn
197+
out' = out . (" " ++)
198+
-- |Number of spaces the target name including whitespace should have.
199+
-- At least twenty, maybe more if target names are long. At most length of the longest target plus five.
200+
space :: Int
201+
space = maximum (20 : map ((+ 5) . length . fst) targets)
202+
203+
-- |Show a target.
204+
-- Concatenates the target with its help message and inserts whitespace between them.
205+
showTarget :: (String, String) -> String
206+
showTarget (target, msg) =
207+
target ++ replicate (space - length target) ' ' ++ msg
208+
209+
-- |Target for a specific ghc version
210+
hieTarget :: String -> (String, String)
211+
hieTarget version =
212+
("hie-" ++ version, "Builds hie for GHC version " ++ version ++ " only")
213+
214+
-- All targets with their respective help message.
215+
targets =
216+
[ ( "build"
217+
, "Builds hie for all supported GHC versions (8.2.1, 8.2.2, 8.4.2, 8.4.3, 8.4.4, 8.6.1, 8.6.2 and 8.6.3)"
218+
)
219+
, ( "build-all"
220+
, "Builds hie and hoogle databases for all supported GHC versions"
221+
)
222+
, ("cabal", "NOTE 3: This is needed for stack only projects too")
223+
, ( "build-docs"
224+
, "Builds the Hoogle database for all supported GHC versions"
225+
)
226+
, ("test" , "Runs hie tests")
227+
, ("icu-macos-fix", "Fixes icu related problems in MacOS")
228+
, ("dist", "Creates a tarball containing all the hie binaries")
229+
, ("help" , "Show help")
230+
]
231+
++ map hieTarget hieVersions
220232

221233
execStackWithYaml_ :: VersionNumber -> [String] -> Action ()
222234
execStackWithYaml_ versionNumber args = do

0 commit comments

Comments
 (0)