Skip to content
This repository
Browse code

Select Configuration file via env var CABAL_CONFIG.

  • Loading branch information...
commit 1dc46087064845ab4942687e79f182e28e89332c 1 parent cdacc20
Paolo Losi authored February 23, 2009
15  cabal-install/Distribution/Client/Config.hs
@@ -74,7 +74,7 @@ import Data.Maybe
74 74
 import Data.Monoid
75 75
          ( Monoid(..) )
76 76
 import Control.Monad
77  
-         ( when, foldM )
  77
+         ( when, foldM, liftM )
78 78
 import qualified Data.Map as Map
79 79
 import qualified Distribution.Compat.ReadP as Parse
80 80
          ( option )
@@ -88,6 +88,8 @@ import Network.URI
88 88
          ( URI(..), URIAuth(..) )
89 89
 import System.FilePath
90 90
          ( (</>), takeDirectory )
  91
+import System.Environment
  92
+         ( getEnvironment )
91 93
 import System.IO.Error
92 94
          ( isDoesNotExistError )
93 95
 
@@ -228,11 +230,20 @@ defaultRemoteRepo = RemoteRepo name uri
228 230
 
229 231
 loadConfig :: Verbosity -> Flag FilePath -> Flag Bool -> IO SavedConfig
230 232
 loadConfig verbosity configFileFlag userInstallFlag = addBaseConf $ do
231  
-  configFile <- maybe defaultConfigFile return (flagToMaybe configFileFlag)
  233
+  let sources = [
  234
+        ("commandline option",   return . flagToMaybe $ configFileFlag),
  235
+        ("env var CABAL_CONFIG", lookup "CABAL_CONFIG" `liftM` getEnvironment),
  236
+        ("default config file",  Just `liftM` defaultConfigFile) ]
232 237
 
  238
+      getSource [] = error "no config file path candidate found."
  239
+      getSource ((msg,action): xs) = 
  240
+                        action >>= maybe (getSource xs) (return . (,) msg)
  241
+
  242
+  (source, configFile) <- getSource sources
233 243
   minp <- readConfigFile mempty configFile
234 244
   case minp of
235 245
     Nothing -> do
  246
+      notice verbosity $ "Config file path source is " ++ source ++ "."
236 247
       notice verbosity $ "Config file " ++ configFile ++ " not found."
237 248
       notice verbosity $ "Writing default configuration to " ++ configFile
238 249
       commentConf <- commentSavedConfig

0 notes on commit 1dc4608

Please sign in to comment.
Something went wrong with that request. Please try again.