[commit: Cabal] master: Actually write some fields to the config file. (e16f93c)
Ian Lynagh
igloo at earth.li
Fri Jun 24 01:46:00 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/Cabal
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/e16f93c1eb373e4bbe96cb803978aa5fef3cc9fc
>---------------------------------------------------------------
commit e16f93c1eb373e4bbe96cb803978aa5fef3cc9fc
Author: bjorn <bjorn at bringert.net>
Date: Sun Oct 7 09:04:30 2007 +0000
Actually write some fields to the config file.
>---------------------------------------------------------------
.../src/Network/Hackage/CabalInstall/Config.hs | 17 +++++++++++++----
.../src/Network/Hackage/CabalInstall/Utils.hs | 5 +++++
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/cabal-install/src/Network/Hackage/CabalInstall/Config.hs b/cabal-install/src/Network/Hackage/CabalInstall/Config.hs
index 50bdb71..0fb2fcd 100644
--- a/cabal-install/src/Network/Hackage/CabalInstall/Config.hs
+++ b/cabal-install/src/Network/Hackage/CabalInstall/Config.hs
@@ -181,7 +181,8 @@ loadConfig configFile =
minp <- readFileIfExists configFile
case minp of
Nothing -> do hPutStrLn stderr $ "Config file " ++ configFile ++ " not found."
- writeDefaultConfigFile configFile
+ hPutStrLn stderr $ "Writing default configuration to " ++ configFile ++ "."
+ writeDefaultConfigFile configFile defaultConf
return defaultConf
Just inp -> case parseBasicStanza configFieldDescrs defaultConf inp of
ParseOk ws dummyConf ->
@@ -200,12 +201,20 @@ loadConfig configFile =
return defaultConf
-- FIXME: finish this
-writeDefaultConfigFile :: FilePath -> IO ()
-writeDefaultConfigFile file =
- do writeFile file ""
+writeDefaultConfigFile :: FilePath -> ConfigFlags -> IO ()
+writeDefaultConfigFile file cfg =
+ writeFile file $ showFields configWriteFieldDescrs cfg
+-- | All config file fields.
configFieldDescrs :: [FieldDescr ConfigFlags]
configFieldDescrs =
+ [
+ ] ++ configWriteFieldDescrs
+
+-- | The subset of the config file fields that we write out
+-- if the config file is missing.
+configWriteFieldDescrs :: [FieldDescr ConfigFlags]
+configWriteFieldDescrs =
[ simpleField "compiler"
(text . show) parseCompilerFlavor
configCompiler (\c cfg -> cfg { configCompiler = c })
diff --git a/cabal-install/src/Network/Hackage/CabalInstall/Utils.hs b/cabal-install/src/Network/Hackage/CabalInstall/Utils.hs
index 1cbb958..e400559 100644
--- a/cabal-install/src/Network/Hackage/CabalInstall/Utils.hs
+++ b/cabal-install/src/Network/Hackage/CabalInstall/Utils.hs
@@ -10,6 +10,7 @@ import Control.Monad (foldM, guard)
import Data.Char (isSpace)
import Data.Maybe (listToMaybe)
import System.IO.Error (isDoesNotExistError)
+import Text.PrettyPrint.HughesPJ
isVerbose cfg = configVerbose cfg >= verbose
@@ -59,3 +60,7 @@ setField _ x s =
lookupFieldDescr :: [FieldDescr a] -> String -> Maybe (FieldDescr a)
lookupFieldDescr fs n = listToMaybe [f | f@(FieldDescr name _ _) <- fs, name == n]
+
+
+showFields :: [FieldDescr a] -> a -> String
+showFields fs x = render $ vcat [ text name <> text ":" <+> get x | FieldDescr name get _ <- fs]
More information about the Cvs-libraries
mailing list