Skip to content

Commit 8b13cb3

Browse files
authored
Merge pull request #8280 from haskell/mergify/bp/3.8/pr-8277
cabal init -i: add the GHC2021 language option (backport #8277)
2 parents 1cace0b + fbada7a commit 8b13cb3

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

cabal-install/src/Distribution/Client/Init/Interactive/Command.hs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE LambdaCase #-}
1+
{-# LANGUAGE LambdaCase, MultiWayIf #-}
22
-----------------------------------------------------------------------------
33
-- |
44
-- Module : Distribution.Client.Init.Command
@@ -413,17 +413,22 @@ testDirsPrompt flags = getTestDirs flags $ do
413413

414414
languagePrompt :: Interactive m => InitFlags -> String -> m Language
415415
languagePrompt flags pkgType = getLanguage flags $ do
416-
lang <- promptList ("Choose a language for your " ++ pkgType)
417-
["Haskell2010", "Haskell98"]
418-
(DefaultPrompt "Haskell2010")
416+
let h2010 = "Haskell2010"
417+
h98 = "Haskell98"
418+
ghc2021 = "GHC2021 (requires at least GHC 9.2)"
419+
420+
l <- promptList ("Choose a language for your " ++ pkgType)
421+
[h2010, h98, ghc2021]
422+
(DefaultPrompt h2010)
419423
Nothing
420424
True
421425

422-
case lang of
423-
"Haskell2010" -> return Haskell2010
424-
"Haskell98" -> return Haskell98
425-
l | all isAlphaNum l -> return $ UnknownLanguage l
426-
_ -> do
426+
if
427+
| l == h2010 -> return Haskell2010
428+
| l == h98 -> return Haskell98
429+
| l == ghc2021 -> return GHC2021
430+
| all isAlphaNum l -> return $ UnknownLanguage l
431+
| otherwise -> do
427432
putStrLn
428433
$ "\nThe language must be alphanumeric. "
429434
++ "Please enter a different language."

cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,15 +912,15 @@ interactiveTests srcDb = testGroup "Check top level getter functions"
912912
]
913913
, testGroup "Check languagePrompt output"
914914
[ testNumberedPrompt "Language indices" (`languagePrompt` "test")
915-
[Haskell2010, Haskell98]
915+
[Haskell2010, Haskell98, GHC2021]
916916
, testSimplePrompt "Other language"
917917
(`languagePrompt` "test") (UnknownLanguage "Haskell2022")
918-
[ "3"
918+
[ "4"
919919
, "Haskell2022"
920920
]
921921
, testSimplePrompt "Invalid language"
922922
(`languagePrompt` "test") Haskell2010
923-
[ "3"
923+
[ "4"
924924
, "Lang_TS!"
925925
, "1"
926926
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# cabal init
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $
4+
withSourceCopyDir "app" $ do
5+
cwd <- fmap testSourceCopyDir getTestEnv
6+
7+
buildOut <- withDirectory cwd $ do
8+
cabalWithStdin "init" ["-i"]
9+
"2\n\n5\n\n\n2\n\n\n\n\n\n\n\n3\n\n"
10+
11+
assertFileDoesContain (cwd </> "app.cabal") "GHC2021"

changelog.d/issue-8265

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
synopsis: cabal init -i: add the GHC2021 language option
2+
packages: cabal-install
3+
prs: #8277
4+
issues: #8265

0 commit comments

Comments
 (0)