Commit bfc13826 authored by Brent Yorgey's avatar Brent Yorgey Committed by tibbe

cabal init: add support for default-language field

parent 78bad98a
......@@ -63,6 +63,7 @@ import Distribution.ModuleName
import Distribution.InstalledPackageInfo
( InstalledPackageInfo, sourcePackageId, exposed )
import qualified Distribution.Package as P
import Language.Haskell.Extension ( Language(..) )
import Distribution.Client.Init.Types
( InitFlags(..), PackageType(..), Category(..) )
......@@ -127,6 +128,7 @@ extendFlags pkgIx =
>=> getSynopsis
>=> getCategory
>=> getLibOrExec
>=> getLanguage
>=> getGenComments
>=> getSrcDir
>=> getModulesBuildToolsAndDeps pkgIx
......@@ -242,7 +244,24 @@ getLibOrExec flags = do
return $ flags { packageType = maybeToFlag isLib }
-- | Ask whether to generate explanitory comments.
-- | Ask for the base language of the package.
getLanguage :: InitFlags -> IO InitFlags
getLanguage flags = do
lang <- return (flagToMaybe $ language flags)
?>> maybePrompt flags
(either UnknownLanguage id `fmap`
(promptList "What base language is the package written in"
[Haskell2010, Haskell98]
(Just Haskell2010)
display
True
)
)
?>> return (Just Haskell2010)
return $ flags { language = maybeToFlag lang }
-- | Ask whether to generate explanatory comments.
getGenComments :: InitFlags -> IO InitFlags
getGenComments flags = do
genComments <- return (not <$> (flagToMaybe $ noComments flags))
......@@ -678,6 +697,10 @@ generateCabalFile fileName c =
, fieldS "build-tools" (listFieldS (buildTools c'))
(Just "Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.")
False
, field "default-language" (language c')
(Just "Base language which the package is written in.")
True
]
listField :: Text s => Maybe [s] -> Flag String
......
......@@ -22,6 +22,7 @@ import Distribution.Verbosity
import qualified Distribution.Package as P
import Distribution.License
import Distribution.ModuleName
import Language.Haskell.Extension ( Language(..) )
import qualified Text.PrettyPrint as Disp
import qualified Distribution.Compat.ReadP as Parse
......@@ -53,6 +54,7 @@ data InitFlags =
, category :: Flag (Either String Category)
, packageType :: Flag PackageType
, language :: Flag Language
, exposedModules :: Maybe [ModuleName]
, otherModules :: Maybe [ModuleName]
......@@ -90,6 +92,7 @@ instance Monoid InitFlags where
, synopsis = mempty
, category = mempty
, packageType = mempty
, language = mempty
, exposedModules = mempty
, otherModules = mempty
, dependencies = mempty
......@@ -114,6 +117,7 @@ instance Monoid InitFlags where
, synopsis = combine synopsis
, category = combine category
, packageType = combine packageType
, language = combine language
, exposedModules = combine exposedModules
, otherModules = combine otherModules
, dependencies = combine dependencies
......
......@@ -1052,6 +1052,14 @@ initCommand = CommandUI {
(\v flags -> flags { IT.packageType = v })
(noArg (Flag IT.Executable))
, option [] ["language"]
"Specify the default language."
IT.language
(\v flags -> flags { IT.language = v })
(reqArg "LANGUAGE" (readP_to_E ("Cannot parse language: "++)
(toFlag `fmap` parse))
(flagToList . fmap display))
, option ['o'] ["expose-module"]
"Export a module from the package."
IT.exposedModules
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment