[commit: Cabal] master: Add a cabal init question about whether to generate comments (a8b0d85)
Ian Lynagh
igloo at earth.li
Fri Jun 24 02:09:17 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/Cabal
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/a8b0d852a5f1087765c9a004e465531e66e0ba88
>---------------------------------------------------------------
commit a8b0d852a5f1087765c9a004e465531e66e0ba88
Author: Duncan Coutts <duncan at community.haskell.org>
Date: Tue May 17 00:20:50 2011 +0000
Add a cabal init question about whether to generate comments
Users will typically only want this the first time they use cabal init.
>---------------------------------------------------------------
cabal-install/Distribution/Client/Init.hs | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/cabal-install/Distribution/Client/Init.hs b/cabal-install/Distribution/Client/Init.hs
index 6f68d54..be31724 100644
--- a/cabal-install/Distribution/Client/Init.hs
+++ b/cabal-install/Distribution/Client/Init.hs
@@ -94,6 +94,7 @@ extendFlags = getPackageName
>=> getSynopsis
>=> getCategory
>=> getLibOrExec
+ >=> getGenComments
>=> getSrcDir
>=> getModulesAndBuildTools
@@ -206,6 +207,14 @@ getLibOrExec flags = do
return $ flags { packageType = maybeToFlag isLib }
+-- | Ask whether to generate explanitory comments.
+getGenComments :: InitFlags -> IO InitFlags
+getGenComments flags = do
+ genComments <- return (flagToMaybe $ noComments flags)
+ ?>> maybePrompt flags (promptYesNo "Include documentation on what each field means y/n" (Just False))
+ ?>> return (Just False)
+ return $ flags { noComments = maybeToFlag (fmap not genComments) }
+
-- | Try to guess the source root directory (don't prompt the user).
getSrcDir :: InitFlags -> IO InitFlags
getSrcDir flags = do
@@ -254,6 +263,18 @@ maybePrompt flags p =
promptStr :: String -> Maybe String -> IO String
promptStr = promptDefault' Just id
+-- | Create a yes/no prompt with optional default value.
+--
+promptYesNo :: String -> Maybe Bool -> IO Bool
+promptYesNo =
+ promptDefault' recogniseYesNo showYesNo
+ where
+ recogniseYesNo s | s == "y" || s == "Y" = Just True
+ | s == "n" || s == "N" = Just False
+ | otherwise = Nothing
+ showYesNo True = "y"
+ showYesNo False = "n"
+
-- | Create a prompt with optional default value that returns a value
-- of some Text instance.
prompt :: Text t => String -> Maybe t -> IO t
More information about the Cvs-libraries
mailing list